Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receive File via SFTP/SSH and automatically forward to FTP on another server

Tags:

sftp

ftp

I'm currently in a situation where I receive flat files via FTP from my clients. A couple of clients have insisted on the need to use SSH Private Key SFTP rather than regular FTP.

What I want to do is setup a web server (preferably in linux/unix but I guess I can do it on a windows server and purchase SFTP server software) that will do the following:

  1. Allow me to setup an SFTP directory for each client with unique user/pass. Each directory also has to have the public/private key SSH "stuff" I'm a little new to this but I've googled it.

  2. Once the file is completely uploaded by the client, I want to kick off an event that ftp's that file via regular FTP to my Windows cloud.

  3. These files can be up to 10mb so the even that ftp's to the other server can't fire until the file is completely uploaded.

Has anyone set something like this up? Any guidance would be appreciated.

Thanks!

like image 232
Robert Avatar asked May 01 '11 16:05

Robert


People also ask

Can I use SFTP to connect to FTP server?

In order to make a secure connection to a FTP server, you can use any application that support SFTP. SFTP (commonly referred to as Secure File Transfer Protocol ) can perform secure file transfers. For secure transfers, it uses Secure Shell (SSH) and supports the SCP protocol in addition to SFTP.

Is SFTP FTP over SSH?

SFTP (SSH File Transfer Protocol) is a secure file transfer protocol. It runs over the SSH protocol. It supports the full security and authentication functionality of SSH. SFTP has pretty much replaced legacy FTP as a file transfer protocol, and is quickly replacing FTP/S.


1 Answers

In Linux, you can use incron to monitor the directory the files will be SFTP'd to and have it trigger your ftp job. It's kind of like cron except that instead of triggering jobs based on time, it does so based on filesystem modifications. In order to only trigger once the entire file has been written, I think you can use IN_CLOSE_WRITE in the inotify mask. Failing this, I suggest configuring events for each of the events individually to echo a message to a log file and see if you can identify one which reliably happens only at the end of the SFTP transfer.

If you're using RedHat, it's not in the standard distribution, but it is in EPEL.

like image 94
Owen Fraser-Green Avatar answered Oct 08 '22 09:10

Owen Fraser-Green