gpt4 book ai didi

c# 在 ftping 之前重命名文件

转载 作者:行者123 更新时间:2023-11-30 21:10:55 25 4
gpt4 key购买 nike

如何在将文件实际传输到服务器之前将文件重命名为时间戳或随机唯一编号?

示例:如果我选择 C:\taco.pdf ..... 1321981871.pdf 实际上是 ftp 到服务器的内容。

FileInfo toUpload = new FileInfo(this.txtFile.Text);

FtpWebRequest request =
(FtpWebRequest)WebRequest.Create(
"ftp://192.168.0.186" + "/" + toUpload.Name
);

request.Method = WebRequestMethods.Ftp.UploadFile;

request.Credentials =
new NetworkCredential("myuser","mypassword");

Stream ftpStream = request.GetRequestStream();
FileStream file = File.OpenRead(this.txtFile.Text);

int length = 1024;
byte[] buffer = new byte[length];
int bytesRead = 0;


do
{
bytesRead = file.Read(buffer, 0, length);
ftpStream.Write(buffer, 0, bytesRead);
}
while (bytesRead != 0);

file.Close();
ftpStream.Close();

最佳答案

如果你只想用不同的名称​​上传文件而不在本地重命名,你就不能改变

 FtpWebRequest request = 
(FtpWebRequest)WebRequest.Create(
"ftp://192.168.0.186" + "/" + toUpload.Name
);

 FtpWebRequest request = 
(FtpWebRequest)WebRequest.Create(
"ftp://192.168.0.186/whatever file name you want");

?

关于c# 在 ftping 之前重命名文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8230780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com