EldoS | Feel safer!

Software components for data protection, secure storage and transfer

CopyRemoteFile() Not working

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#33754
Posted: 06/23/2015 17:59:01
by Ian Halfpenny (Basic support level)
Joined: 06/23/2015
Posts: 2

string remoteDir = "/Download/";

byte[] Handle;
ArrayList AListing = new ArrayList();
Handle = SftpClient.OpenDirectory(remoteDir);
SftpClient.ReadDirectory(Handle, AListing);
if (AListing.Count > 0)
{
System.Console.WriteLine("Contents of " + remoteDir + ":");
for (int i = 0; i < AListing.Count; i++)
{
Console.Write(((TElSftpFileInfo)AListing[i]).Name + " ");
Console.WriteLine(((TElSftpFileInfo)AListing[i]).Attributes.Directory);




if (((TElSftpFileInfo)AListing[i]).Attributes.Directory == false)
{
string remoteFileName = "/Download/" + ((TElSftpFileInfo)AListing[i]).Name;
string localFileName = "c:\\" + ((TElSftpFileInfo)AListing[i]).Name;

if (File.Exists(localFileName) == true)
{
File.Delete(localFileName);
}

try
{
SftpClient.DownloadFile(remoteFileName, localFileName);
}
catch (Exception ex)
{
Console.WriteLine("SFTP download failed with message [" + ex.Message + "]", true);
}

//string remoteMoveTo = "/Download/History/" + ((TElSftpFileInfo)AListing[i]).Name;
string Source = "/Download/" + ((TElSftpFileInfo)AListing[i]).Name;
string Destination = "/History" + ((TElSftpFileInfo)AListing[i]).Name;
try
{
SftpClient.CopyRemoteFile(Source, Destination, true);
}
catch (Exception ex)
{
Console.WriteLine("Copy to Download History Directory on SFTP Server [" + ex.Message + "]", true);
}


try
{
SftpClient.RemoveFile(remoteFileName);
}
catch (Exception ex)
{
Console.WriteLine("SFTP remove failed with message [" + ex.Message + "]", true);
}


}


#33755
Posted: 06/23/2015 18:17:41
by Ken Ivanov (EldoS Corp.)

Hi Ian,

Thank you for contacting us.

Representing a non-native function (remote file copying functionality is standardised via SFTP extension mechanism and is not a built-in protocol feature), CopyRemoteFile() requires explicit support on the server side to work. If the vendor of the SFTP server chose not to implement the extension, this function will not be available for the clients connecting to it. Your server does not seem to implement the extension, so I am afraid you have to find a different approach to copying data remotely in your case.

Ken

Reply

Statistics

Topic viewed 1048 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!