在线等。。
请各位指导。。先说谢谢了。 。
8 个解决方案
#2
import org.apache.commons.io.IOUtils;
import org.apache.commons.net.ftp.FTPClient;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileOutputStream;
public class FtpTest {
public static void main(String[] args) {
testUpload();
testDownload();
}
/**
* FTP上传单个文件测试
*/
public static void testUpload() {
FTPClient ftpClient = new FTPClient();
FileInputStream fis = null;
try {
ftpClient.connect("192.168.14.117");
ftpClient.login("admin", "123");
File srcFile = new File("C:\\new.gif");
fis = new FileInputStream(srcFile);
//设置上传目录
ftpClient.changeWorkingDirectory("/admin/pic");
ftpClient.setBufferSize(1024);
ftpClient.setControlEncoding("GBK");
//设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.storeFile("3.gif", fis);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("FTP客户端出错!", e);
} finally {
IOUtils.closeQuietly(fis);
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
}
}
}
/**
* FTP下载单个文件测试
*/
public static void testDownload() {
FTPClient ftpClient = new FTPClient();
FileOutputStream fos = null;
try {
ftpClient.connect("192.168.14.117");
ftpClient.login("admin", "123");
String remoteFileName = "/admin/pic/3.gif";
fos = new FileOutputStream("c:/down.gif");
ftpClient.setBufferSize(1024);
//设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.retrieveFile(remoteFileName, fos);
fos.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("FTP客户端出错!", e);
} finally {
IOUtils.closeQuietly(fos);
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
}
}
}
}
import org.apache.commons.net.ftp.FTPClient;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileOutputStream;
public class FtpTest {
public static void main(String[] args) {
testUpload();
testDownload();
}
/**
* FTP上传单个文件测试
*/
public static void testUpload() {
FTPClient ftpClient = new FTPClient();
FileInputStream fis = null;
try {
ftpClient.connect("192.168.14.117");
ftpClient.login("admin", "123");
File srcFile = new File("C:\\new.gif");
fis = new FileInputStream(srcFile);
//设置上传目录
ftpClient.changeWorkingDirectory("/admin/pic");
ftpClient.setBufferSize(1024);
ftpClient.setControlEncoding("GBK");
//设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.storeFile("3.gif", fis);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("FTP客户端出错!", e);
} finally {
IOUtils.closeQuietly(fis);
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
}
}
}
/**
* FTP下载单个文件测试
*/
public static void testDownload() {
FTPClient ftpClient = new FTPClient();
FileOutputStream fos = null;
try {
ftpClient.connect("192.168.14.117");
ftpClient.login("admin", "123");
String remoteFileName = "/admin/pic/3.gif";
fos = new FileOutputStream("c:/down.gif");
ftpClient.setBufferSize(1024);
//设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.retrieveFile(remoteFileName, fos);
fos.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("FTP客户端出错!", e);
} finally {
IOUtils.closeQuietly(fos);
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
}
}
}
}
#3
只要找到上传的位置不就好办了
要是找不到位置
恐怕得不到吧
通过资源定位符应该是很好做的
要是找不到位置
恐怕得不到吧
通过资源定位符应该是很好做的
#4
这图片是如何打印显示在页面上的。。要用IO流来输出吗?
新手,请指教。。
新手,请指教。。
#5
顶..
#6
public File getFtpFile(String name) throws IOException
{
// 连接ftp服务器并读取log文件
FtpClient fc = new FtpClient(ftpUrl, 21);
fc.login("ftpUser", "ftpPass");
fc.cd("images");
TelnetInputStream tis = fc.get(name);
// 写log文件到本地
File fGetted = new File("D:\\" + name);
RandomAccessFile fGet = new RandomAccessFile(fGetted, "rw");
fGet.seek(0);
DataInputStream puts = new DataInputStream(tis);
int ch;
while ((ch = puts.read()) >= 0)
{
fGet.write(ch);
}
puts.close();
fGet.close();
tis.close();
fc.closeServer();
return fGetted;
}
#7
读的怎么全都是文件啊!
我知道怎么去读文件,可就是图片不会读,思维没有倒过来,图片和文件是同一个概念,可就不会读。。
哎!
我知道怎么去读文件,可就是图片不会读,思维没有倒过来,图片和文件是同一个概念,可就不会读。。
哎!
#8
public static void main(String[] args) {
String content = "";
try {
String server = "192.168.0.100";
String user = "backup";
String password = "backup123";
String path = "/Smile/txt/";
String filename = "ExamineDaoImpl.java";
String charsetName = "GBK";
String port="21";
String line;
StringBuffer buffer = new StringBuffer();
FtpClient ftpClient = new FtpClient();
ftpClient.openServer(server);
ftpClient.login(user, password);
// ftpClient.login(arg0, arg1)
ftpClient.cd(path);
TelnetInputStream in = ftpClient.get(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(
in, charsetName));
for (int i = 0; (line = reader.readLine()) != null; i++) {
buffer.append(line);
buffer.append("\n");
}
content = buffer.toString();
reader.close();
in.close();
ftpClient.closeServer();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(content);
}
这是读出FTP上的一个文件,我要如何改成读FTP上的图片了。。
#1
#2
import org.apache.commons.io.IOUtils;
import org.apache.commons.net.ftp.FTPClient;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileOutputStream;
public class FtpTest {
public static void main(String[] args) {
testUpload();
testDownload();
}
/**
* FTP上传单个文件测试
*/
public static void testUpload() {
FTPClient ftpClient = new FTPClient();
FileInputStream fis = null;
try {
ftpClient.connect("192.168.14.117");
ftpClient.login("admin", "123");
File srcFile = new File("C:\\new.gif");
fis = new FileInputStream(srcFile);
//设置上传目录
ftpClient.changeWorkingDirectory("/admin/pic");
ftpClient.setBufferSize(1024);
ftpClient.setControlEncoding("GBK");
//设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.storeFile("3.gif", fis);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("FTP客户端出错!", e);
} finally {
IOUtils.closeQuietly(fis);
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
}
}
}
/**
* FTP下载单个文件测试
*/
public static void testDownload() {
FTPClient ftpClient = new FTPClient();
FileOutputStream fos = null;
try {
ftpClient.connect("192.168.14.117");
ftpClient.login("admin", "123");
String remoteFileName = "/admin/pic/3.gif";
fos = new FileOutputStream("c:/down.gif");
ftpClient.setBufferSize(1024);
//设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.retrieveFile(remoteFileName, fos);
fos.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("FTP客户端出错!", e);
} finally {
IOUtils.closeQuietly(fos);
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
}
}
}
}
import org.apache.commons.net.ftp.FTPClient;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileOutputStream;
public class FtpTest {
public static void main(String[] args) {
testUpload();
testDownload();
}
/**
* FTP上传单个文件测试
*/
public static void testUpload() {
FTPClient ftpClient = new FTPClient();
FileInputStream fis = null;
try {
ftpClient.connect("192.168.14.117");
ftpClient.login("admin", "123");
File srcFile = new File("C:\\new.gif");
fis = new FileInputStream(srcFile);
//设置上传目录
ftpClient.changeWorkingDirectory("/admin/pic");
ftpClient.setBufferSize(1024);
ftpClient.setControlEncoding("GBK");
//设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.storeFile("3.gif", fis);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("FTP客户端出错!", e);
} finally {
IOUtils.closeQuietly(fis);
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
}
}
}
/**
* FTP下载单个文件测试
*/
public static void testDownload() {
FTPClient ftpClient = new FTPClient();
FileOutputStream fos = null;
try {
ftpClient.connect("192.168.14.117");
ftpClient.login("admin", "123");
String remoteFileName = "/admin/pic/3.gif";
fos = new FileOutputStream("c:/down.gif");
ftpClient.setBufferSize(1024);
//设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.retrieveFile(remoteFileName, fos);
fos.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("FTP客户端出错!", e);
} finally {
IOUtils.closeQuietly(fos);
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
}
}
}
}
#3
只要找到上传的位置不就好办了
要是找不到位置
恐怕得不到吧
通过资源定位符应该是很好做的
要是找不到位置
恐怕得不到吧
通过资源定位符应该是很好做的
#4
这图片是如何打印显示在页面上的。。要用IO流来输出吗?
新手,请指教。。
新手,请指教。。
#5
顶..
#6
public File getFtpFile(String name) throws IOException
{
// 连接ftp服务器并读取log文件
FtpClient fc = new FtpClient(ftpUrl, 21);
fc.login("ftpUser", "ftpPass");
fc.cd("images");
TelnetInputStream tis = fc.get(name);
// 写log文件到本地
File fGetted = new File("D:\\" + name);
RandomAccessFile fGet = new RandomAccessFile(fGetted, "rw");
fGet.seek(0);
DataInputStream puts = new DataInputStream(tis);
int ch;
while ((ch = puts.read()) >= 0)
{
fGet.write(ch);
}
puts.close();
fGet.close();
tis.close();
fc.closeServer();
return fGetted;
}
#7
读的怎么全都是文件啊!
我知道怎么去读文件,可就是图片不会读,思维没有倒过来,图片和文件是同一个概念,可就不会读。。
哎!
我知道怎么去读文件,可就是图片不会读,思维没有倒过来,图片和文件是同一个概念,可就不会读。。
哎!
#8
public static void main(String[] args) {
String content = "";
try {
String server = "192.168.0.100";
String user = "backup";
String password = "backup123";
String path = "/Smile/txt/";
String filename = "ExamineDaoImpl.java";
String charsetName = "GBK";
String port="21";
String line;
StringBuffer buffer = new StringBuffer();
FtpClient ftpClient = new FtpClient();
ftpClient.openServer(server);
ftpClient.login(user, password);
// ftpClient.login(arg0, arg1)
ftpClient.cd(path);
TelnetInputStream in = ftpClient.get(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(
in, charsetName));
for (int i = 0; (line = reader.readLine()) != null; i++) {
buffer.append(line);
buffer.append("\n");
}
content = buffer.toString();
reader.close();
in.close();
ftpClient.closeServer();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(content);
}
这是读出FTP上的一个文件,我要如何改成读FTP上的图片了。。