2
  1. I download all files in remote dir1/.
  2. They are downloaded to a directory which contains hundreds of files.
  3. I need to copy the file to a remote "archive" directory.
  4. I need to delete the file from dir1/ (above).

I'm having trouble finding a way to transfer a file from dir1/file to dir2/ using sftp protocol.

I"ve tried lftp because I need to provide password non-interactively, and public/private keys aren't available for me. sftp's rename is available, but it requires public/private key auth.

I cannot use lftp's ftpcopy, cp, or mv. In the man page, get seems promising:

get README -o ftp://some.host.org/debian-dir/

But authentication fails (assume "no password").

Because I am using the same server, it would be nice if lftp just used the same credentials that I am currently using to log into the current server. But alas...

Is there a way to use a password for get command? Is there a better way to do this?

I do not believe that rsync is helpful here...

If it helps, I believe that the SFTP server is a Windows box.

7
  • For using password with OpenSSH sftp, see stackoverflow.com/questions/5386482/… Commented Jun 24, 2014 at 5:56
  • "it would be nice if lftp just used the same credentials that I am currently using to log into the current server": So what you need SFTP for, if you are already logged onto the server? Use local (server's) file copying commands (copy on Windows). Commented Jun 24, 2014 at 5:58
  • I'm not logged onto the Windows desktop... I'm authenticated with sftp to the sftp server. Commented Jun 25, 2014 at 1:04
  • I am aware of sshpass and we are considering this as an alternative option. I was just wondering if there was any other way that I had not yet considered. Commented Jun 25, 2014 at 1:05
  • So, what's wrong about sshpass? Why it's only alternative for you? Please make your question more clear. Also do you need to copy (get) or move the file? Why cannot you use lftp's mv command? Commented Jun 25, 2014 at 7:13

1 Answer 1

1

@Felipe - I dunno what I was smoking when I posted my comment, I can't believe I didn't finish typing my post, sorry about that.

When I was trying to get lftp working to transfer files between my remote server and local computer I ran into authentication issues after starting lftp, I could successfully connect to my server with lftp but I couldn't run any commands, everything would play out like the example below.

lftp 222.222.222.222:~> ls
'ls' at 0 [Connecting...]
'ls' at 0 [Delaying before reconnect: 35]

Exit out of lftp and back to the normal command line, then try connecting with ssh using this command, enter your password if prompted -

ssh -p PORT# [email protected]

If you are able to connect to your remote server and are able to list the contents of the current folder, you should now be able to use lftp without the 'connecting' timeout error.

I have attached the script I use to transfer files/folders between my remote and local computers. The script isn't completely finalized but it does work as intended. Remember to edit the host,port#, username/password, local and remote directories (additionally lines 23,24 and 25 might need to be commented out, but don't try unless you run into problems)

At some point I would like the script to be able to pull a list of folders from another text file and then transfer each folder listed to my local computer however found and edited for my needs run the script attached in the link below.

To remove the files from the remote server after transferring you can use this flag with the mirror command.

'mirror --remove-source-files'

lftp-mirror.sh - script

The LFTP Manual might be helpful with getting the right command and aurguments for your particular situation.

LFTP Manual

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .