我想通过xmodem协议传输文件,我发现 ExtraPutty 提供了一个名为 UploadFiles 的功能,以使开发人员可以使用它来去做。但是我遇到了一个问题,就是我的程序无法通过此功能传输文件。这是我的源代码:
[DllImport(@"C:\Program Files\ExtraPuTTY\Bin\ExtraPuTTY.dll", EntryPoint = "UploadFiles")]
public static extern int UploadFile(UInt32 connectionId, int protocolType, string pathFile, string title, string comments);
static void TransferFirmware()
{
//Establish a connection with target device
string targetName = "169.254.x.x";
UInt32 connectionId = new UInt32();
string login = string.Empty;
string password = string.Empty;
byte showTerminal = 0;
Int32 protocol = 3;
UInt32 portNum = 950;
Int32 generateReport = 0;
FOTAHandler.CallBackRcvData callback = new FOTAHandler.CallBackRcvData(RcvData);
UInt32 specSetting = 0;
var connectionResult = FOTAHandler.OpenConnection(targetName, ref connectionId, login, password, showTerminal, protocol, portNum, generateReport, ref callback, specSetting);
if (connectionResult == 0)
{
Console.WriteLine("Connection id: " + Convert.ToString(connectionId));
Console.WriteLine("The connection is okay. Start uploading image file...");
try
{
var result = FOTAHandler.UploadFile(connectionId, 0, @"ImageFile\V00.bin", "XXXX", "XXXX XXXXXXXX");
Console.WriteLine(String.Format("File transfer result: {0}", result));
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
else
{
Console.WriteLine("The connection fail. Error code: " + connectionResult);
}
}
有人知道吗?非常感谢!