本文整理汇总了C#中FtpClient.PutFile方法的典型用法代码示例。如果您正苦于以下问题:C# FtpClient.PutFile方法的具体用法?C# FtpClient.PutFile怎么用?C# FtpClient.PutFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FtpClient
的用法示例。
在下文中一共展示了FtpClient.PutFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
public static Stream Write(string path)
{
var diskpath = Paths.Map(path);
if (Paths.IsWritable(path)) return new FileStream(diskpath, FileMode.Create, FileAccess.Write);
else if (CanUseFtp) {
var pipe = new PipeStream();
Tasks.Do(() => {
using (pipe)
using (var ftp = new FtpClient()) {
string dir, name;
ftp.Split(path, out dir, out name);
ftp.ChangeDirectory(dir);
ftp.PutFile(pipe, name, Ftp.FileAction.Create);
ftp.Close();
}
});
return pipe;
}
throw new IOException(string.Format("Path {0} is write protected.", path));
}
示例2: UploadFile
public void UploadFile(string filePath)
{
if (!_hasAlreadyFixedStrings)
FixProperties();
var ftp = new FtpClient(Host, Port, Protocol)
{
DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active,
FileTransferType = TransferType.Binary,
Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null
};
try
{
ftp.Open(Username, Password.ConvertToUnsecureString());
ftp.ChangeDirectoryMultiPath(Directory);
ftp.PutFile(filePath, FileAction.Create);
}
finally
{
ftp.Close();
}
}
示例3: Save
public static void Save(Stream src, string path)
{
if (Paths.IsWritable(path)) {
SaveRaw(src, Paths.Map(path));
} else if (CanUseFtp) {
using (var ftp = new FtpClient()) {
string dir, name;
ftp.Split(path, out dir, out name);
ftp.ChangeDirectory(dir);
ftp.PutFile(src, name, Ftp.FileAction.Create);
ftp.Close();
}
} else throw new IOException(string.Format("Path {0} is write protected.", path));
}
示例4: InternalMoveContent
public void InternalMoveContent(string directory, string aimPath)
{
foreach (FtpItem item in ListDirectoriesAndFiles(directory, false)
.Where(
item => item.FullPath != aimPath && item.FullPath != aimPath.Substring(aimPath.Length - 1)))
{
FtpClient ftp = null;
try
{
ftp = new FtpClient(Host, Port, Protocol)
{
DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active,
FileTransferType = TransferType.Binary,
Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null
};
ftp.Open(Username, Password.ConvertToUnsecureString());
Guid guid; // Just for the out-reference of TryParse
if (item.ItemType == FtpItemType.Directory && UpdateVersion.IsValid(item.Name))
{
ftp.ChangeDirectoryMultiPath(aimPath);
if (!IsExisting(aimPath, item.Name))
ftp.MakeDirectory(item.Name);
ftp.ChangeDirectoryMultiPath(item.Name);
InternalMoveContent(item.FullPath, String.Format("{0}/{1}", aimPath, item.Name));
DeleteDirectory(item.FullPath);
}
else if (item.ItemType == FtpItemType.File &&
(item.Name == "updates.json" || Guid.TryParse(item.Name.Split('.')[0], out guid)))
// Second condition determines whether the item is a package-file or not
{
if (!IsExisting(aimPath, item.Name))
{
// "MoveFile"-method damages the files, so we do it manually with a work-around
//ftp.MoveFile(item.FullPath, String.Format("{0}/{1}", aimPath, item.Name));
string localFilePath = Path.Combine(Path.GetTempPath(), item.Name);
ftp.GetFile(item.FullPath, localFilePath, FileAction.Create);
ftp.PutFile(localFilePath, String.Format("{0}/{1}", aimPath, item.Name),
FileAction.Create);
File.Delete(localFilePath);
}
DeleteFile(item.ParentPath, item.Name);
}
}
finally
{
if (ftp != null)
ftp.Close();
}
}
}