Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
1.4k views
in General by (120 points)
I need to copy multiple files from a remote sftp server and afterwards move the files on the remote server to a different folder. When the job is finished I would like to receive an email as well. This is a scheduled process that only needs to run once a month but for each run I would like to have a separate log file. What is the best way? FTP, powershell or Javascript?

At the moment I'm using FTP in combination with mget, change folder, mput, change folder again and mdelete but that's not the most beautifull way to do so. How should I do this? Does anyone have a simple example?

I'm no scripting expert. Thanks in advance!
by (51.5k points)
The most elegant solutions to this requirement would involve customizing the remote server - probably using scripts.  Do you have control of the remote server?
by (120 points)
The remote server is not ours, I only have writing permissions on the ftp share.

Transfering the files and moving them on the remote server is all initiated on our side using competeFTP. I guess if I would like to send a confirmation email when the job was succesfull I can't use an ftp script but need to use javascript or powershell. Is this correct or is there another solution?
by (162k points)
With CompleteFTP you can send a confirmation email once the upload has succeeded - see the User Guide->Events->How to set up email notifications.
by (120 points)
I know that but now I use a scheduled process trigger to check for files on a remote ftp server and user using a ftp script so I don't  believe completeFTP detects the file downloads thus not sending any notifications...

I know sending emails works, already used it before.
by (51.5k points)
Are you saying that your script downloads the files from the remote server to FTP, and then you're expecting the download to trigger an e-mail notification?
by (120 points)
No I don't think it works that way but support2 suggested I would use email notifications.
Am I wrong?
by (162k points)
I didn't realise you were using a script on CompleteFTP to fetch files from another server. You could do this in Javascript, and at the end send an email. The API allows you to send emails, see here:
https://enterprisedt.com/products/completeftp/doc/guide/jssapi/mail.html

1 Answer

0 votes
by (51.5k points)

CompleteFTP's Javascript environment (JSS) includes both an FTP client and an Email client, so you can write a script that downloads files and then sends an email when it's done.

Here's sample script that downloads a file (adapted from this):

var ftp = new Ftp();
ftp.hostName = "myftpserver";
ftp.protocol = "SFTP";
ftp.userName = "myusername";
ftp.password = "mypassword";
try {
  ftp.connect();
} catch (e) {
  throw "Could not connect to server.";
}
try {
  ftp.download("myfile.dat", "/home/myusername/myfile.dat");
  console.log("Download complete");
} catch (e) {
  throw "Error while downloading file.";
}
ftp.close();

and here's a sample script that sends an email (from here)

mail.smtp.server = "smtp.gmail.com";
mail.smtp.port = 587;
mail.smtp.userName = "my.account@gmail.com";
mail.smtp.password = "my.password";
mail.smtp.enableSSL = true;

mail.send("my.account@gmail.com", "recipient@test.com", "Test message", "This is a test");

You should be able to put these two together to get the desired result.

by (120 points)
Awesome! Thank you very much, I will take a look at it next week and come back to you.

Categories

...