Need Help With SFTP UploadFile
Posted: Wed 12 Sep 2012 18:02
I am new to dealing with sftp. I found a couple of helpful forums and came up with this code to upload a file to an sftp site. I dropped on the TScSSHClient and TScSFTPClient components, naming them respectively to SSHClient and SFTPClient and then call this code from another form that sends in the host, user, password and file to be uploaded. I know I am getting a connection because the function; SFTPClient->DownloadFile("/TransferTest.txt", "C:\\TransferTest.txt", true );
works great and I pull the file right to my C drive. It is only on the upload that I recieve the error in my catch "Cannot send data to server". This is pretty vague so I don't know what part is not right? Can someone tell me if they see anything in this code that could be causing this error?
This was built on RAD Studio XE2
works great and I pull the file right to my C drive. It is only on the upload that I recieve the error in my catch "Cannot send data to server". This is pretty vague so I don't know what part is not right? Can someone tell me if they see anything in this code that could be causing this error?
This was built on RAD Studio XE2
Code: Select all
bool TfrmFTPSend::SendSFTPFile(UnicodeString host, UnicodeString user, UnicodeString pass, UnicodeString locFile)
{
bool successful = true;
TScFileStorage *KeyFileStorage = new TScFileStorage(this);
SSHClient->KeyStorage = KeyFileStorage;
SSHClient->Authentication = atPassword;
SSHClient->Port = 22;
SSHClient->HostName = host;
SSHClient->User = user;
SSHClient->Password = pass;
SFTPClient->SSHClient = SSHClient;
try
{
// Initialize session
SSHClient->Connect();
SFTPClient->Initialize();
// send file
SFTPClient->UploadFile(locFile, L"", false);
}
catch (Exception &E)
{
ErrMsg(ETYPE_ERROR, 0, E.Message, "", "");
successful = false;
}
catch (...)
{
successful = false;
}
// Finish/cleanup
SFTPClient->Disconnect();
SSHClient->Disconnect();
delete SFTPClient;
delete SSHClient;
delete KeyFileStorage;
return successful;
}