Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.5k views
in .NET FTP by (840 points)
Hi,

I have a requirement of creating the zip folder of one specific folder present on FTP Server. The zip folder should also be created in the same path where that source folder exists. Can you please provide any help regarding the same.

Thanks,
Tanu

9 Answers

0 votes
by (51.6k points)
Hi Tanu

NOTE: This reply relates to CompleteFTP rather than edtFTPnet/PRO. Your mention of 'zip folder' had me convinced your question related to CompleteFTP since that's the name of a feature in that software, but my colleague later pointed out that you posted in the edtFTPnet/PRO forum. I'll reply regarding edtFTPnet/PRO in my second reply below.

We don't have an inbuilt way to do this, but it is possible to add the feature yourself if you have the Enterprise Edition. You can do it using the Custom Command Script feature.

The script you'd add is the following:
function ZipFolder(zipFilePath, folderPath) {
  var zipFile = new Ionic.Zip.ZipFile(zipFilePath);
  zipFile.AddDirectory(folderPath);
  zipFile.Save();
}

Once you've entered and applied this script it can be called as an FTP site command, an SSH command or an HTTP URL as follows:
FTP:
  site ZipFolder C:\\MyZipDirectory\\MyFile.zip C:\\MyDataDirectory
  (MS's FTP client requires 'quote site' instead of 'site')

SSH:
  ZipFolder C:\\MyZipDirectory\\MyFile.zip C:\\MyDataDirectory

HTTP:
  http://localhost/CustomCommand/ZipFolder?zipFilePath=C:\MyZipDirectory\MyFile.zip&folderPath=C:\MyDataDirectory

Unfortunately, as you can see, the paths of the two arguments have to be Windows paths rather than paths in CompleteFTP's file-system. This is because the current version of CompleteFTP (i.e. version 8.1.0) doesn't provide a means of converting between the two types of paths. Let me know if you'd like to pursue this direction and you're unhappy with the fact that you have to use Windows paths. We may be able to add a function for you to be able to convert between the two for you.

- Hans (EnterpriseDT)
0 votes
by (51.6k points)
edtFTPnet/PRO version of the answer :)

A client can't create zip folders on the server unless the server has a specialized site command to do it (as described in my reply above). This is because this feature is not a part of the FTP protocol specification. If the server does provide such a command then you should be able to call it as a site command. edtFTPnet/PRO supports site command using the InvokeSiteCommand method.

If you were calling the custom command that I described above then you'd do it like this:
myFTPConnection.InvokeSiteCommand("ZipFolder", "C:\\MyZipDirectory\\MyFile.zip", "C:\\MyDataDirectory");

But exactly what the arguments would be depends on how the server you're connected to does it.

- Hans (EnterpriseDT)
0 votes
by (840 points)
Ok. I have an EXE doing the zip task. I have already purchased the PRO version.

I want to run exe present on my ftp server from my ASP.NET webAPI. Or rather to say want to invoke exe present on FTP server from my code.
Can i use InvokeCommandSSH? if yes how to use it? or Is there any other option to run that EXE.
Thanks!
0 votes
by (162k points)
Are you connecting to your server via SFTP? You need to check that your SFTP server permits exec'ing of binaries, and determine what path to use.
0 votes
by (840 points)
Yes I am connecting to the server via SFTP.
My code looks like:
SecureFTPConnection sftp = new SecureFTPConnection();

sftp.ServerAddress = ftpBaseIP;
sftp.UserName = ftpUsername;
sftp.Password = ftpPassword;
// set the protocol to SCP
sftp.Protocol = FileTransferProtocol.SCP;


if (sftp.IsConnected)
sftp.Close();
sftp.Timeout = 0;
sftp.Connect();



string[] args = { "tanutest" };

sftp.InvokeCommandSSH(new Uri("D:/Temp/ConsoleApplicationForFTP.exe").AbsolutePath, args);

Am i missing something here.
Is there any mismatch in syntax.

Also how to check that the SFTP server permits exec'ing of binaries, and as mentioned above i need to use D:/Temp of FTP Server.

Thanks,
Tanu
0 votes
by (162k points)
Here's an example

string[] parameters = new string[2];
parameters[0] = "<time_stamp>";
parameters[1] = "<file_Path>";
string reply = ftpConnection.InvokeCommandSSH("chmtime ", parameters);

It is unlikely that the server will let you arbitrarily execute commands like zip on arbitrary directories - that would be a significant security hole. You may need to talk to the server administrator to find out if what you want to do is possible.
0 votes
by (840 points)
Failed to connect to XXX.XX.XX.XX:XX within timeout -1 ms

at sftp.Connect();

Don't know why?
This is when i am using :
// set the protocol to SCP
sftp.Protocol = FileTransferProtocol.SCP;
0 votes
by (840 points)
When not setting the above protocol mentioned i am getting : "SFTP/SCP protocol required for InvokeCommandSSH" at:
string reply = sftp.InvokeCommandSSH("chmtime ", parameters);

:(
0 votes
by (162k points)
You need to use SFTP.

But your server may not support exec'ing remote commands - you need to check with the server administrator to see if 1) it can and 2) the location of the zip exe

Also 'chmtime ' was just an example of how to invoke a remote command - the actual command you will be using is 'zip ' or 'gzip ' or something like that (depending on what is supported on the server).

Categories

...