Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I'm having trouble ftp(ing) uploading a text file to the correct location I can view the locations via FileZilla. I wrote a test script that runs a method called 'UploadToFTPSite' this is the TEST SCRIPT code:

C#
public void UploadToFTPSiteSuccess()
{
   //Arrange
   var ibxMedOut = IbxUploadController.GetDataToUpload();
   var stringData = IbxUploadController.ConvertDataToString(ibxMedOut);
   string fileFolder = "ibxuploadFolder";
   string fileName = "Test.txt";
   string host = "99.9.9.99"; 
   int port = 22;
   string user = "*****";
   string password = "*****";

   //Assign
   IbxUploadController.UploadToFTPSite(fileFolder, fileName, stringData, host, port, user, password);

   //Assert
}

This my is my Method I'm trying to run:
C#
public static void UploadToFTPSite(string pFileFolder, string pFileName, string pContents, string pHost, int pPort, string pUser, string pPassword)
{
   string currentProcess = "Starting";
   try
   {
      ConnectionInfo connectionInfo = new PasswordConnectionInfo(pHost, pPort, pUser, pPassword);
      currentProcess = "ConnectionInfo created";
      string pather;
      using (var client = new SftpClient(connectionInfo))
      {
         currentProcess = "SftpClient created";
         client.Connect();
         currentProcess = "Connected";
                  
         currentProcess = "WorkingDirectory: " + client.WorkingDirectory;
         client.ChangeDirectory(pFileFolder);
         client.Create(pFileName);
         client.AppendAllText(pFileName, pContents);
         currentProcess = "Data appended";
         client.Disconnect();
         currentProcess = "Disonnected";
      }
   }
   catch (Exception ex)
//etc.

The problem is I can upload my file to the root folder, but I'm trying to specify a sub folder inside the root folder to upload my file to, but I can't get my file to upload to a any folder but the root folder. I think it may have something to do with the "Client.WorkingDirectory" even though when I debug it the Client has the location where I want the file to go to.

Thanks. Any suggestions would be appreciated!
Posted
Updated 9-Feb-21 12:56pm
v3
Comments
ZurdoDev 7-Nov-14 12:07pm    
Any errors?
Commish13 7-Nov-14 15:22pm    
No errors. Just doesn't go to the correct location.
BillWoodruff 7-Nov-14 12:35pm    
Have you thought about posting a question to the RenciSSH discussion forum:

https://sshnet.codeplex.com/discussions
Commish13 7-Nov-14 15:22pm    
I will now. Didn't know there was one.

Not sure if it is the same error but I just added the remote directory to the file name itself for my upload to work.

Change Directory seems to have no effect on the current directory.
 
Share this answer
 
Try to add "/" before subfolder name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900