Hi Hans,
I've come across edtFTPNet while looking for a free ftp software usable in my .NET codes.
This is my first day using it, and I've used FTPConnection, then FTPClient, then back to FTPConnection.
I'm having this problem on both FTPClient and FTPConnection: the Put file size is smaller than the Get file size.
To clarify matters, I'm using this great software on VMS files. I'm on a tight deadline, and I'd appreciate very much any and all help that I can get. Below are my code functions, as derived from the examples. As mentioned, for both FTPClient and FTPConnection, the results are the same. So pls, pls, pls, help me!
Thanks!
Eutychus
public static bool ftpGet(string servername, string username, string password, string filename)
{
FTPClient ftp = null;
try
{
ftp = new FTPClient(servername);
// login
ftp.Login(username, password);
// set up passive ASCII transfers
ftp.TransferType = FTPTransferType.ASCII;
// copy file from server
ftp.Get(filename, filename);
// Shut down client
ftp.Quit();
return true;
}
catch (Exception ex)
{
if (ftp.IsConnected) { ftp.Quit(); }
Console.WriteLine(ex.Message);
return false;
}
}
public static bool ftpPut(string servername, string username, string password, string filename)
{
FTPClient ftp = null;
try
{
ftp = new FTPClient(servername);
// login
ftp.Login(username, password);
// set up passive ASCII transfers
ftp.TransferType = FTPTransferType.ASCII;
// copy file to server
ftp.Put(filename, filename);
// Shut down client
ftp.Quit();
return true;
}
catch (Exception ex)
{
if (ftp.IsConnected) { ftp.Quit(); }
Console.WriteLine(ex.Message);
return false;
}
}
public static bool ftpGet2(string servername, string username, string password, string filename)
{
FTPConnection ftp = null;
try
{
ftp = new FTPConnection();
ftp.ServerAddress = servername;
ftp.UserName = username;
ftp.Password = password;
ftp.Connect();
// set up passive ASCII transfers
ftp.ConnectMode = FTPConnectMode.PASV;
ftp.TransferType = FTPTransferType.ASCII;
// copy file from server
ftp.DownloadFile(filename, filename);
// Shut down client
ftp.Close();
return true;
}
catch (Exception ex)
{
if (ftp.IsConnected) { ftp.Close(); }
Console.WriteLine(ex.Message);
return false;
}
}
public static bool ftpPut2(string servername, string username, string password, string filename)
{
FTPConnection ftp = null;
try
{
ftp = new FTPConnection();
ftp.ServerAddress = servername;
ftp.UserName = username;
ftp.Password = password;
ftp.Connect();
// set up passive ASCII transfers
ftp.ConnectMode = FTPConnectMode.PASV;
ftp.TransferType = FTPTransferType.ASCII;
// copy file to server
ftp.UploadFile(filename, filename);
// Shut down client
ftp.Close();
return true;
}
catch (Exception ex)
{
if (ftp.IsConnected) { ftp.Close(); }
Console.WriteLine(ex.Message);
return false;
}
}