Hi, Iam trying to get my transfer to work, but every time I run the program it gives me a Access denied. (code=550) error when it gets to the ftp1.UploadFile(zipfileName, fname).
What I am trying to do is get my transfer to resume after a network connection has been lost and then restored. I test this by plugging out my network cable when I am running the first UploadFile, it then goes into the catch area where it tries to get the connection first (I plug in my cable again) , and then it should resume the transfer. If I run my code and do not try to simulate a lost connection my upload works 100%. Please help !!!!! Here is my coding:
if (ftp.IsConnected == true)
{
ftp.TransferType = FTPTransferType.BINARY;
try
{
ftp.ChangeWorkingDirectory(objFTPDetails.Directory);
}
catch
{
}
int start = zipfileName.LastIndexOf("\\");
string fname = zipfileName.Substring(start + 1);
try
{
ftp.UploadFile(zipfileName, fname);
ftp.Close();
}
catch (System.Exception ex1)
{
GetConnection(ftp, objFTPDetails);
ResumePut(ftp, objFTPDetails, zipfileName);
}
}
public static void GetConnection(FTPConnection ftp, CalicoWS.FTP objFTPDetails)
{
string x = ftp.IsConnected.ToString();
if (bool.Parse(x) == true)
{
try
{
ftp.Close();
}
catch
{
}
}
while (ftp.IsConnected == false)
{
try
{
ftp.Connect();
}
catch
{
}
}
}
public static void ResumePut(FTPConnection ftp, CalicoWS.FTP objFTPDetails, string zipfileName)
{
ftp.Close();
ftp.Dispose();
//Here I totally create a new connection , just incase, tried it with old connection, gave same error
CalicoWS.CalicoWS objWS = new FTPResume.CalicoWS.CalicoWS();
CalicoWS.FTP objFTPDetails1 = new FTPResume.CalicoWS.FTP();
objFTPDetails1 = objWS.getDaybookFTPDetails(FTPResume.Settings.InstanceID);
FTPResume.Settings.FtpConnect = "True";
FTPConnection ftp1 = new FTPConnection();
ftp1.ServerAddress = objFTPDetails1.Hostname;
ftp1.UserName = objFTPDetails1.Username;
ftp1.Password = objFTPDetails1.Password;
ftp1.ServerPort = objFTPDetails1.Port;
ftp1.DeleteOnFailure = false;
ftp1.Connect();
if (ftp1.IsConnected == true)
{
try
{
ftp1.ChangeWorkingDirectory(objFTPDetails1.Directory);
}
catch
{
}
ftp1.TransferType = FTPTransferType.BINARY;
int start = zipfileName.LastIndexOf("\\");
string fname = zipfileName.Substring(start + 1);
try
{
if (ftp1.Exists(fname) == true)
{
ftp1.ResumeTransfer();
ftp1.UploadFile(zipfileName, fname); \\ Here it boms out
}
else
{
}
ftp1.Close();
}
catch (System.Exception ex1)
{
ftp1.Close();
}
}
}