Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: posting to 4 FTP connections error

Yes, please upgrade.
But anyway, the error you mention (The process cannot access the file ...) has nothing to do with the failure of the transfer.

File or folder '\\cifsch\Encoded\wmv\disneysecretofthewingsDISNEY_de_sd169_22_25_20.wmv' does not exist.
System Error. Code: 2.
The system cannot find the file specified
chiragchandani

posting to 4 FTP connections error

yes i have 4 instances of the session class

I have also noted the FTP.cs which is instantiated through various clients calling them and also the debug log for the first three

You will see the error in 2nd and 3rd FTP.

I read on the release notes that in version 5.14 some problem of this type might be solved. Is that correct? Should i install the new version?

I am already using the new DLL but the installation is of an old version


Thanks

public class FTP
{
Session _session = new Session();
SessionOptions _options;
TransferOptions _transferOptions;
public string _remoteDirectory = string.Empty;

public FTP(string _hostName, string _password, int _portNumber, string _userName, string _debugPath, string _sessionPath)
{
_session.DebugLogPath = String.Format(_debugPath, "WINSCP_Level3_Debuglog" + DateTime.Now.ToString("MMddyyyyHHmmss"));
_session.SessionLogPath = String.Format(_sessionPath, "WINSCP_Level3_Sessionlog" + DateTime.Now.ToString("MMddyyyyHHmmss"));
_session.DisableVersionCheck = true;
_session.DefaultConfiguration = false;
_session.ExecutablePath = ConfigurationManager.AppSettings["ExecutableProperty"];
_session.Timeout = System.TimeSpan.FromMilliseconds(60000);
try
{
_session.Open(Initialize(_hostName, _password, _portNumber, _userName));
}
catch (Exception ex)
{
throw ex;
}
}

private SessionOptions Initialize(string _hostName, string _password, int _portNumber, string _userName)
{
_options = new SessionOptions();
_options.Protocol = Protocol.Ftp;
_options.Password = _password;
_options.HostName = _hostName;
_options.PortNumber = _portNumber;
_options.UserName = _userName;
return _options;
}

private TransferOptions SetTOptions()
{
_transferOptions = new TransferOptions();
_transferOptions.TransferMode = TransferMode.Automatic;
//_transferOptions.PreserveTimestamp = true;
return _transferOptions;
}

public bool UploadFile(string temporary_path, string _filename, bool directory2Upload)
{
TransferOperationResult transferResult;

string dirPath2UploadFrom = String.Empty;
string dirPath2Upload2 = String.Empty;
string temporaryFileName = String.Empty;
string dirPath2Move = String.Empty;
string filePath = String.Empty;

bool replaceFileOnTransfer = false;

FileInfo uploadfile;
FileInfo temporary_pathDir;

Random r = new Random();

try
{
temporary_pathDir = new FileInfo(temporary_path);

temporaryFileName = temporary_pathDir.DirectoryName + @"\" + r.Next(100).ToString();

File.Copy(temporary_path, temporaryFileName);

Utils.LogFile("New Temporary File: " + temporaryFileName);

temporary_path = temporaryFileName;

uploadfile = new FileInfo(_filename);

replaceFileOnTransfer = Boolean.Parse(ConfigurationManager.AppSettings["ReplaceFilesOnTransfer"]);

if (!_remoteDirectory.Equals(String.Empty))
filePath = _remoteDirectory + @"/" + uploadfile.Directory.Name + @"/" + Path.GetFileName(_filename);
else
filePath = uploadfile.Directory.Name + @"/" + Path.GetFileName(_filename);

Utils.LogFile("[Info] [UploadFile]: Local Path: " + temporary_path);
Utils.LogFile("[Info] [UploadFile]: Remote Path: " + filePath);

if (replaceFileOnTransfer)
{
transferResult = _session.PutFiles(temporary_path, filePath, true, SetTOptions());
Utils.LogFile("[Info] [DeleteFile]: Deleted File Name: " + filePath + " as replaceFileOnTransfer is True");
transferResult.Check();
}
else
{
if (_session.FileExists(filePath))
{
Utils.LogFile("[Info] [UploadFile]: Movie Name " + Path.GetFileName(_filename) + " already exists on the remote location and has not been transferred");
return true;
}
else
{
transferResult = _session.PutFiles(temporary_path, filePath, false, SetTOptions());
transferResult.Check();
}
}

Utils.LogFile("[Info] [UploadFile]: Movie Name " + Path.GetFileName(_filename) + " has been tansferred through FTP");

if (directory2Upload)
{
dirPath2UploadFrom = temporary_pathDir.DirectoryName + @"\" + Path.GetFileNameWithoutExtension(temporary_pathDir.Name);
dirPath2Move = temporary_pathDir.DirectoryName + @"\" + r.Next(100).ToString();
dirPath2Upload2 = _remoteDirectory + @"/" + uploadfile.Directory.Name + @"/" + Path.GetFileNameWithoutExtension(temporary_pathDir.Name);

//Directory.Move(dirPath2UploadFrom, dirPath2Move);

Utils.LogFile("New Dir Name: " + dirPath2Move);

if (Directory.Exists(dirPath2UploadFrom))
{
if (replaceFileOnTransfer)
{
transferResult = _session.PutFiles(dirPath2UploadFrom, dirPath2Upload2, true, SetTOptions());
Utils.LogFile("[Info] [DeleteFile]: Deleted Directory: " + dirPath2Upload2 + " as replaceFileOnTransfer is True");
transferResult.Check();
}
else
{
if (_session.ListDirectory(dirPath2UploadFrom) != null)
{
Utils.LogFile("[Info] [UploadFile]: Movie Name " + Path.GetFileName(_filename) + " already exists on the remote location and has not been transferred");
return true;
}
else
{
transferResult = _session.PutFiles(dirPath2UploadFrom, dirPath2Upload2, false, SetTOptions());
transferResult.Check();
}
}
}

// Directory.Move(dirPath2Move, dirPath2UploadFrom);
Utils.LogFile("[Info] [UploadFile]: Movie Name " + Path.GetFileName(_filename) + " fragments been tansferred through FTP");
}
File.Delete(temporary_path);
Utils.LogFile("Deleted new temporary file");
return true;
}
catch (Exception ex)
{
Utils.LogFile("Exception on File Upload: " + ex.Message);
throw ex;
}
}

private bool DeleteFile(string f)
{
File.Delete(f);
return true;
}

/// <summary>
///
/// </summary>
public void KillSession()
{
Process[] _process = Process.GetProcessesByName("WinSCP");

try
{
_process.All(Kill);
Utils.LogFile("[Info] [KillWINSCP] WINSCP EXE process closed and Killed");
}
catch (Exception ex)
{
throw ex;
}
}

/// <summary>
///
/// </summary>
/// <param name="_p"></param>
private bool Kill(Process _p)
{
_p.Kill();
_p = null;
if (_p == null)
return true;
else
return false;
}
}
martin

Re: posting to 4 FTP connections error

Do you have 4 instances of Session class?
Please attach (or email me) debug log (Session.DebugLogPath) of all 4 instances.
chiragchandani

posting to 4 FTP connections error

I pick 1 directory or file and it is intended to transfer to 4 different FTP connections through WINSCP tool. I am using the .NET DLL in a windows service application in C#

First FTP transfer succeeds and then on at the second one throws the following error in the WINSCP Debug log:

The process cannot access the file "C:\Users.......\wscp230F0.00418AD3"

Please assist on how to resolve that problem

Thanks