in reply to Re: rput on foreign sftp in perl
in thread rput on foreign sftp in perl

Thank you so much for the information. I need to use the RPUT command since I am transferring a series of directories and files from one linux server to another and the RPUT is working, but I need to have the target server receive the files with permissions set to CHMOD 777. Is there a way using perl SFTP to do a recurrsive chmod command on the directories I just transferred over?

Replies are listed 'Best First'.
Re^3: rput on foreign sftp in perl
by kcott (Archbishop) on Sep 18, 2013 at 01:43 UTC
    "I need to use the RPUT command since I am transferring a series of directories ..."

    The only rput() in your code is:

    $sftp->rput($source_ftp_file, $destination_ftp_file, ...

    If $source_ftp_file and $destination_ftp_file are supposed to be directories, then they are poorly named: consider $source_ftp_dir and $destination_ftp_dir.

    "... and the RPUT is working, ..."

    Your original post said: "When sending the files over, the target files are being wiped out with a 0 bytes but not replaced with the source file.". That doesn't sound like it's working.

    "... but I need to have the target server receive the files with permissions set to CHMOD 777."

    Both put() and rput() have various options relating to permissions. I've already supplied a link to the documentation.

    -- Ken

      Thank you for the reply and for your the suggestions on the names, the doc does refer to using the umask parameters for controlling permissions, but in researching the umask command I saw the following: - The umask command cannot grant extra permissions beyond what is specified by the program that creates the file or directory. If you need to make permission changes to existing file use the chmod command. - some of the files I am dealing with are replacement files and using umask does not allow it to be changed to 0777(the best I can get to is 0755). I am trying to use the sftp 'chmod' command but not getting good results, I am supplying the 'chmod' command the full path on the linux server, but it is coming back saying the file does not exist, although I think that is a generic error supplied to state it was not successful (Couldn't setstat remote file (chmod): No such file) . The second topic of the file arriving with a 0 length, I did see a post http://www.tek-tips.com/viewthread.cfm?qid=1674115 that if a file is owned by someone other than me but they are in the same group (ie. I can read/write to the file), this will cause the put (rput) command to not be allowed to change the permissions on the file, thus getting the 0 length file. I followed the suggestions on the post (in below command line in the code), but I am still receiving the 0 length. Also changed the Unix.pm file to have a buffer value of 4096 and still getting zero length files.

      $sftp->rput($source_ftp_dir, $destination_ftp_dir, copy_perm => 0, cop +y_time => 0) $sftp->chmod($full_path_dest_file, 0777) or die "count not chmod file +\n" . $sftp->error;

        Firstly, I'm not convinced that $source_ftp_file is, in fact, a directory. Everything in your code suggests otherwise:

        ... foreach my $file (@files) { my $source_ftp_file = $inputDir . "/". $file; ... # put file to server $sftp->rput($source_ftp_file, ... ... }

        I suggest you use the file test operators to check this.

        If they are files, use put() with an absolute value for the perm option. If you can't change the permissions of an existing file, perhaps you can delete it first. If you can't do either of those, perhaps there's a reason that you'll need to discuss with a system administrator.

        If they are directories, and you can't satisfactorily transfer them with a single rput(), perhaps you'll need to walk the directory structure and transfer them individually with put() as described in the preceding paragraph.

        -- Ken