Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int Upload(String HostName, String UserName, String Password, String remotePath, String localFilePath)
- {
- int result = 0;
- Session session = null;
- try
- {
- // Setup session options
- SessionOptions sessionOptions = new SessionOptions
- {
- Protocol = Protocol.Ftp,
- HostName = HostName,
- UserName = UserName,
- Password = Password,
- Timeout = TimeSpan.MaxValue,
- };
- using (session = new Session())
- {
- // Connect
- session.Open(sessionOptions);
- // upload files
- TransferOptions transferOptions = new TransferOptions();
- transferOptions.TransferMode = TransferMode.Ascii;
- TransferOperationResult transferResult = null;
- transferResult = session.PutFiles(localFilePath, remotePath, false, transferOptions);
- // Throw on any error
- transferResult.Check();
- // Print results
- foreach (TransferEventArgs transfer in transferResult.Transfers)
- {
- Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
- }
- }
- result = 0;
- }
- catch (Exception e)
- {
- Console.WriteLine("Error: {0}", e);
- result = 1;
- }
- finally
- {
- if (session != null)
- {
- session.Dispose();
- }
- }
- return result;
- }
- at System.TimeSpan.Add(TimeSpan ts)
- at System.TimeSpan.op_Addition(TimeSpan t1, TimeSpan t2)
- at WinSCP.Session.CheckForTimeout(String additional)
- at WinSCP.PatientFileStream.Wait(Int32& interval)
- at WinSCP.PatientFileStream.Read(Byte[] array, Int32 offset, Int32 count)
- at System.Xml.XmlTextReaderImpl.ReadData()
- at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
- at System.Xml.XmlTextReaderImpl.ParseText()
- at ProjectName.Upload(String HostName, String UName, String Password, String remotePath, String localFilePath)
Add Comment
Please, Sign In to add comment