1

I'm using ncftpput to upload local file in my Linux server to FTP. Is there any way to do the same but move files\directories withing the FTP? As I've mentioned in the title?

I do aware for the solution of "ncftp rename" but it's not good for me as I can't use it in the my bash scripts.

ncftpput is great for upload local files but it's not supporting moving\coping files from remote-dir to remote-dir.

If you have any equivalent\alternatives for ncftpput please share.

Thanks in advance, EddieM

2
  • are you only capable of connecting to this server via ftp or can you connect using ssh as well ? Commented Mar 24, 2016 at 14:21
  • The FTP is a windows server. So no, there is not ssh available. Commented Mar 24, 2016 at 14:24

2 Answers 2

1

Unless there is a reason that you didn't disclose, for using ncftp instead of plain ftp, you can do this by using the plain old ftp in a script, as such:

#!/bin/bash HOST='some.host.name.com' USER='username' PASSWD='password' SOURCE='/home/username/file.ext' TARGET='/var/tmp/file.ext' ftp $HOST <<EOC user $USER $PASSWD rename $SOURCE $TARGET quit EOC # go on with your bash script from this point on 
3
  • Hi Mel, it look like something I can work with. I will check it and update. Thanks for the help. Commented Mar 24, 2016 at 15:54
  • Does it work with moving whole directory? and not only files? Commented Mar 28, 2016 at 8:28
  • I believe rename command of ftp only works on single files. You will need to build in some intelligence into the script to do the renaming of all the files in the directory, one by one. It is not an effective method for massive file operations. Commented Mar 28, 2016 at 13:25
1

You can take advantage of Fuse

Create 2 fuse directory endpoints based both on an ftp connection and then do regular copy commands or something more complex.

Assume you are using a distro based on apt (but is the same with yum, and so on..)


Install the curlftpfs package:

apt-get install curlftpfs 

Create a directory linked to the ftp:

mkdir /mnt/ftp1 

Do the same for the second one:

mkdir /mnt/ftp2 

Connect to the host1 and host2:

curlftpfs user1:pass1@host1 /mnt/ftp1 curlftpfs user2:pass2@host2 /mnt/ftp2 

Do a simple copy command

cp -R /mnt/ftp1/somedir /mnt/ftp2 

When you have finished you can simply unmount the 2 mounts

umount /mnt/ftp1 umount /mnt/ftp2 

Remarks:
This solution use plain ftp, if you want to take extra advantage of encryption you can use ftps with equivalent commands or in case of shell ftp sftp, but you said that one machine is windows so unless using something like cygwin I guess sftp is out of question.

3
  • 1
    Hi, your solution look like an extra effort for my excising solution, but still thanks for the suggestion, I will check it and update! Commented Mar 24, 2016 at 15:57
  • Man, discover fuse and you will find your nirvana :P Is super useful to create such kind of complex setups.. Commented Mar 24, 2016 at 15:58
  • @EddieM excising... you mean existing? Commented Dec 31, 2016 at 14:47

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.