我从这个链接有这个工作代码,将文件上传到ftp站点:
' set up request...
Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create("ftp://ftp.myserver.com/test.txt"), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential("myusername", "mypassword")
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
' read in file...
Dim bFile() As Byte = System.IO.File.ReadAllBytes("C:\Temp\test.txt")
' upload file...
Dim clsStream As System.IO.Stream = _
clsRequest.GetRequestStream()
clsStream.Write(bFile, 0, bFile.Length)
clsStream.Close()
clsStream.Dispose()
Run Code Online (Sandbox Code Playgroud)
我想知道,如果文件已存在于ftp目录中,该文件是否会被覆盖?
我使用ftplib连接到ftp站点.我想获取最近上传的文件并下载它.我能够连接到ftp服务器并列出文件,我也将它们放在一个列表中并获得datefield转换.是否有任何功能/模块可以获取最近的日期并从列表中输出整行?
#!/usr/bin/env python
import ftplib
import os
import socket
import sys
HOST = 'test'
def main():
try:
f = ftplib.FTP(HOST)
except (socket.error, socket.gaierror), e:
print 'cannot reach to %s' % HOST
return
print "Connect to ftp server"
try:
f.login('anonymous','al@ge.com')
except ftplib.error_perm:
print 'cannot login anonymously'
f.quit()
return
print "logged on to the ftp server"
data = []
f.dir(data.append)
for line in data:
datestr = ' '.join(line.split()[0:2])
orig-date = time.strptime(datestr, '%d-%m-%y %H:%M%p')
f.quit()
return
if __name__ == '__main__':
main() …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用下载文件FtpWebRequest.
private void DownloadFile(string userName, string password, string ftpSourceFilePath, string localDestinationFilePath)
{
int bytesRead = 0;
byte[] buffer = new byte[1024];
FtpWebRequest request = CreateFtpWebRequest(ftpSourceFilePath, userName, password, true);
request.Method = WebRequestMethods.Ftp.DownloadFile;
Stream reader = request.GetResponse().GetResponseStream();
BinaryWriter writer = new BinaryWriter(File.Open(localDestinationFilePath, FileMode.CreateNew));
while (true)
{
bytesRead = reader.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
writer.Write(buffer, 0, bytesRead);
}
}
Run Code Online (Sandbox Code Playgroud)
它使用CreateFtpWebRequest我创建的这个方法:
private FtpWebRequest CreateFtpWebRequest(string ftpDirectoryPath, string userName, string password, bool keepAlive = false)
{
FtpWebRequest request = …Run Code Online (Sandbox Code Playgroud) 我可以使用Inno Setup导入.cer文件(证书)吗?
我该怎么做?
我需要为Windows XP,Windows Vista和Windows 7创建证书安装程序.
在Inno Setup启动之前或"select directory"页面之前,我需要将文件复制到一个文件夹.我希望从安装程序复制此文件,而不是从外部源复制,如果有人可以举例.
我使用这段代码:
function NextButtonClick(PageID: Integer): Boolean;
begin
Result := True;
if (PageId = wpWelcome) then
begin
FileCopy(
ExpandConstant('file.exe'),
ExpandConstant('{reg:HKCU\SOFTWARE\XXX,InstallPath}\file.exe'), false);
end;
end;
Run Code Online (Sandbox Code Playgroud)
我希望有人用一个例子给出一个更好的主意.
谢谢你们.
我正在使用Decrypt密码,我坚持这个错误:
字符串长度不能为零.参数名称:oldValue
请帮助解决此错误或建议我另一个解密程序.
这是完整的代码:
string decryptpwd = string.Empty;
UTF8Encoding encodepwd = new UTF8Encoding();
Decoder Decode = encodepwd.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(encryptpwd.Replace("+",""));
int charcount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decode_char = new char[charcount];
Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decode_char, 0);
decryptpwd = new String(decode_char);
return decryptpwd;
Run Code Online (Sandbox Code Playgroud) 我的Windows应用程序经常在使用Wine的*nix上使用.
由于它是一个以文件为中心的应用程序,它经常使用(并呈现给用户)Windows"文档"文件夹(使用时解析CSIDL_PERSONAL).不幸的是,在Wine下,指向假的Wine/Windows目录通常是空的和未使用的.我想将用户指向他的Unix主文件夹.
有没有可靠的方法来找出它在葡萄酒下的位置?
我希望我能读取HOME环境变量,但它不会导出(与大多数其他变量相反)到Windows环境.
目前我猜测家里正在使用Z:\home\%USERNAME%.但这对我来说并不健全.
如果没有办法找到主目录,是否至少有一种方法可以检测Wine根驱动器(Z:默认情况下),所以我不需要硬编码至少一个驱动器部分的路径?
您好我可以使用我自己的用户名使用WinSCP登录GCE VM,无法以root身份登录...默认情况下,根据Google,可以更改.
改变如下:
第1步:登录SSH和Su Root
# sudo su root
Run Code Online (Sandbox Code Playgroud)
第2步:更改密码Root
#passwd root
Run Code Online (Sandbox Code Playgroud)
第3步:配置SSHD允许Root登录
#nano /etc/ssh/sshd_config
PermitRootLogin yes
PasswordAuthentication yes
#service sshd restart (I used ssh as I'm using ubuntu and sshd wouldn't work)
Run Code Online (Sandbox Code Playgroud)
试图通过WinSCP以root身份登录但是我得到了
"收到太大(1349281121 B)SFTP数据包.最大支持的数据包大小为1024000 B.该错误通常是由启动脚本(如.profile)打印的消息引起的.该消息可能以'Plea'开头." 无法初始化SFTP协议.主机是否运行SFTP服务器?"
有任何想法吗?
我有一个文件要下载(从 json 中提取的下载路径。例如:)http://testsite/abc.zip。
我需要帮助才能执行,所有 5 个线程都应将abc.zip文件下载到输出目录,并且下载必须是Asynchronous或concurrent。
目前使用下面的代码,它确实下载了 5 次文件,但它会一一下载(同步)。
我想要的是,同时下载。
def dldr(file=file_url, outputdir=out1):
local_fn = str(uuid.uuid4())
if not os.path.exists(outputdir):
os.makedirs(outputdir)
s = datetime.now()
urllib.urlretrieve(file, outputdir + os.sep + local_fn)
e = datetime.now()
time_diff = e - s
logger(out1, local_fn, time_diff)
for i in range(1, 6):
t = threading.Thread(target=dldr())
t.start()
Run Code Online (Sandbox Code Playgroud)
我正在创建一个窗口服务,用于从 SFTP 服务器下载文件。为此,我正在使用Renci.SshNet,Renci.SshNet.Common和Renci.SshNet.Sftp.
我有这个代码:
String Host = "HostName";
int Port = 22;
String RemoteFileDirectory =
Convert.ToString(ConfigurationManager.AppSettings["SourcePath"]);
String Username = "UserName";
String Password = "*******";
var KeybasedMethod = new KeyboardInteractiveAuthenticationMethod(Username);
KeybasedMethod.AuthenticationPrompt +=
(sender, e) => { e.Prompts.First().Response = password; };
AuthenticationMethod[] methods = new AuthenticationMethod[]
{
new PrivateKeyAuthenticationMethod(Username, new PrivateKeyFile(@"Z:\SFTP SETUP\CJ22")),
KeybasedMethod
};
ConnectionInfo connectionInfo = new ConnectionInfo(hostname, username, methods);
using (var sftp = new SftpClient(connectionInfo))
{
sftp.Connect();
// ...
}
Run Code Online (Sandbox Code Playgroud)
我得到例外。
私钥文件无效。
我无法弄清楚我的代码中缺少什么。
下面是我使用 …
.net ×3
c# ×3
ftp ×3
inno-setup ×2
python ×2
sftp ×2
ssh ×2
asp.net ×1
c#-4.0 ×1
certificate ×1
distribution ×1
encryption ×1
ftplib ×1
http ×1
installation ×1
installer ×1
linux ×1
python-2.7 ×1
root ×1
ssh.net ×1
unix ×1
vb.net ×1
wine ×1
winscp ×1