我需要一些帮助在我的Azure VM实例上设置FTP.
VM是Win Server 2012 R2.我已经设置了Web服务器角色并在IIS中创建了一个FTP站点.我已经确认我可以访问FTP服务器
ftp command: open localhost
Run Code Online (Sandbox Code Playgroud)
我还为配置用于标准端口21的Azure门户上的VM配置了FTP端点.
最后,我打开了一个防火墙规则,允许所有流量进出端口21.
现在,当我尝试从家用机器FTP到它时,我可以看到服务器公共DNS名称正在解析为正确的IP和端口,但是无法建立连接.
我错过了某处的配置步骤吗?
谢谢
任何人都可以解释我以下代码有什么问题吗?我尝试了不同的主机,FTPClientConfigs,它可以通过firefox/filezilla正确访问...问题是我总是得到空文件列表,没有任何异常(files.length == 0).我使用与Maven一起安装的commons-net-2.1.jar.
FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_L8);
FTPClient client = new FTPClient();
client.configure(config);
client.connect("c64.rulez.org");
client.login("anonymous", "anonymous");
client.enterRemotePassiveMode();
FTPFile[] files = client.listFiles();
Assert.assertTrue(files.length > 0);
Run Code Online (Sandbox Code Playgroud) 我正在尝试做一个非常简单的文件上传.我想要一个可以上传我告诉它的任何文件的Java FTPClient.但pdf总是搞砸了,我的pdf编辑器(Adobe)不会打开它,说有一个I/O错误.
我正在使用以下课程:
import org.apache.commons.net.ftp.FTPClient;
....
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect("mydomain.com");
client.login("user", "password");
String filename = "myPDF.pdf";
fis = new FileInputStream(filename);
client.storeFile("temp.pdf", fis);
fis.close();
client.logout();
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用,我该如何解决?
我org.apache.commons.net.ftp.FTPClient
在我的一个应用程序中使用FTP服务器.我能够connect
,login
,pwd
和cwd
.但是,当我尝试list
文件时,它不会返回该目录中的文件列表,我知道确实存在文件.我正在使用该方法FTPFile[] listFiles()
,它返回一个空数组FTPFile
.
请在下面找到我尝试此操作的代码段:
String hostname = properties.getProperty("FTP_SERVER");
String user = properties.getProperty("FTP_USER");
String passwd = properties.getProperty("FTP_PASSWD");
FTPClient client = new FTPClient();
client.connect(hostname);
client.login(user, passwd);
String reply = client.getStatus();
System.out.println(reply);
client.enterRemotePassiveMode();
client.changeWorkingDirectory("/uploads");
FTPFile[] files = client.listFiles();
System.out.println(files.length);
for (FTPFile file : files) {
System.out.println(file.getName());
}
String[] fileNames = client.listNames();
if (fileNames != null) {
for (String file : fileNames) {
System.out.println(file);
}
}
client.disconnect();
Run Code Online (Sandbox Code Playgroud) 我们使用以下Apache Commons Net FTP代码连接到FTP服务器,轮询某些目录以查找文件,如果找到文件,则将它们检索到本地计算机:
try {
logger.trace("Attempting to connect to server...");
// Connect to server
FTPClient ftpClient = new FTPClient();
ftpClient.setConnectTimeout(20000);
ftpClient.connect("my-server-host-name");
ftpClient.login("myUser", "myPswd");
ftpClient.changeWorkingDirectory("/loadables/");
// Check for failed connection
if(!FTPReply.isPositiveCompletion(ftpClient.getReplyCode()))
{
ftpClient.disconnect();
throw new FTPConnectionClosedException("Unable to connect to FTP server.");
}
// Log success msg
logger.trace("...connection was successful.");
// Change to the loadables/ directory where we poll for files
ftpClient.changeWorkingDirectory("/loadables/");
// Indicate we're about to poll
logger.trace("About to check loadables/ for files...");
// Poll for files.
FTPFile[] filesList = …
Run Code Online (Sandbox Code Playgroud) 有没有办法实现安全的FTP org.apache.commons.net.ftp.FTPClient
?
如果没有,Java的其他选项有哪些?
请弄清楚这一点.代码正常运行,没有任何异常.
FTPClient ftp = new FTPClient();
ftp.connect(server);
if(!ftp.login(username, password))
{
ftp.logout();
return false;
}
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply))
{
ftp.disconnect();
return false;
}
InputStream in = new FileInputStream(localfile);
ftp.setFileType(ftp.BINARY_FILE_TYPE, ftp.BINARY_FILE_TYPE);
ftp.setFileTransferMode(ftp.BINARY_FILE_TYPE);
Store = ftp.storeFile(destinationfile, in);
in.close();
ftp.logout();
ftp.disconnect();
}
catch (Exception ex)
{
ex.printStackTrace();
return false;
}
return Store;
Run Code Online (Sandbox Code Playgroud)
Buttttttttt
return语句始终返回false,并且文件未上载到服务器上.有人请帮忙.
为了您的信息,1)我在办公室网络.--->我们需要添加任何代理吗?
File file = new File("C:\\Users\\sg0214273\\Desktop\\seagate\\seagate.txt");
FileInputStream input = new FileInputStream(file);
client.setFileType(FTP.BINARY_FILE_TYPE);
if (!client.storeFile(file.getName(), input)) {
System.out.println("upload failed!");
}
reply = client.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)) {
System.out.println("upload failed!");
} …
Run Code Online (Sandbox Code Playgroud) 如何使用java程序从ftp服务器删除文件?我已成功使用以下代码在ftp上传文件:
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String s = "ftp://username:password@ftpclient:21/text.txt;type=i";
URL u = new URL(s);
URLConnection uc = u.openConnection();
BufferedOutputStream bos = new BufferedOutputStream(uc.getOutputStream());
bos.write(67);
bos.close();
System.out.println("Done");
}
Run Code Online (Sandbox Code Playgroud)
但是如何从这个ftp服务器中删除文件?任何帮助将不胜感激.........提前谢谢
我正在使用Apache Commons FTP上传文件.在上传之前,我想检查服务器上是否已存在该文件,并从该服务器备份到同一服务器上的备份目录.
有谁知道如何将文件从FTP服务器复制到同一台服务器上的备份目录?
public static void uploadWithCommonsFTP(File fileToBeUpload){
FTPClient f = new FTPClient();
FTPFile backupDirectory;
try {
f.connect(server.getServer());
f.login(server.getUsername(), server.getPassword());
FTPFile[] directories = f.listDirectories();
FTPFile[] files = f.listFiles();
for(FTPFile file:directories){
if (!file.getName().equalsIgnoreCase("backup")) {
backupDirectory=file;
} else {
f.makeDirectory("backup");
}
}
for(FTPFile file: files){
if(file.getName().equals(fileToBeUpload.getName())){
//copy file to backupDirectory
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
编辑过的代码:仍有问题,当我备份zip文件时,备份文件已损坏.
有没有人知道它的原因?
public static void backupUploadWithCommonsFTP(File fileToBeUpload) {
FTPClient f = new FTPClient();
boolean backupDirectoryExist = false;
boolean fileToBeUploadExist = …
Run Code Online (Sandbox Code Playgroud) 我想使用FileZilla每天自动将PDF上传到我的GoDaddy托管网站,取代前一天的工作表.有没有办法做到这一点?我在网上看到批处理文件可能有用,有人可以发布批处理文件的样本版本吗?
ftp-client ×10
java ×8
ftp ×6
sftp ×2
automation ×1
azure ×1
filezilla ×1
iis ×1
iis-7.5 ×1
upload ×1