lftp remote copy file from one directory to another

1

  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.

Felipe Alvarez

Posted 2014-06-24T03:26:34.387

Reputation: 1 666

For using password with OpenSSH sftp, see http://stackoverflow.com/questions/5386482/how-to-run-the-sftp-command-with-a-password-from-bash-script

– Martin Prikryl – 2014-06-24T05:56:38.557

"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). – Martin Prikryl – 2014-06-24T05:58:01.043

I'm not logged onto the Windows desktop... I'm authenticated with sftp to the sftp server. – Felipe Alvarez – 2014-06-25T01:04:48.390

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. – Felipe Alvarez – 2014-06-25T01:05:25.887

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? – Martin Prikryl – 2014-06-25T07:13:45.353

I realize this post is a little old but the solution I found seemed worth posting here for future readers. – Woz – 2017-10-26T04:15:15.007

Thanks @Woz. What was the solution that you found? – Felipe Alvarez – 2017-10-31T06:09:54.497

Answers

0

@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# username@xxx.xxx.xxx.xxx

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

Woz

Posted 2014-06-24T03:26:34.387

Reputation: 303