in reply to rput on foreign sftp in perl

See the Net::SFTP::Foreign documentation.

rput() is for recursively transferring directory contents. put() is for transferring individual files.

See also: setcwd() for changing the remote directory and chdir for changing the local directory.

Unrelated to your problem, but readdir has an example using grep which could greatly improve your code populating @files (in particular, you could get rid of the two until loops and the splice operations).

-- Ken

Replies are listed 'Best First'.
Re^2: rput on foreign sftp in perl
by Anonymous Monk on Sep 17, 2013 at 14:54 UTC

    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?

      "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;