●クライアント
FileSystemManager fsm = VFS.getManager();
// hostKeyCheckをnoにしないと、com.jcraft.jsch.JSchException: UnknownHostKeyエラーになる
FileSystemOptions opts = new FileSystemOptions();
SftpFileSystemConfigBuilder builder =
SftpFileSystemConfigBuilder.getInstance();
builder.setStrictHostKeyChecking(opts,"no");
// リモートファイル
FileObject remote = fsm.resolveFile("sftp://user:pass@host/path",opts);
// ローカルファイル
FileObject local = fsm.resolveFile("c:\\path");
// put
remote.copyFrom(local);
大きいファイル(100Mくらい?)をftpするとOutOfMemoryErrorになる。
SftpFileObject.doGetInputStream()でnew ByteArrayOutputStream()しているのが原因。
パッチがあったので、ためしにやってみたら、正常に動作した。
@@ -383,15 +385,19 @@
// TODO - Don't read the entire file into memory. Use the
// stream-based methods on ChannelSftp once they work properly
+
+/*
final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
channel.get(relPath, outstr);
outstr.close();
return new ByteArrayInputStream(outstr.toByteArray());
+*/
+return new SftpInputStream(channel, channel.get(relPath));
}
finally
{
-fileSystem.putChannel(channel);
+//fileSystem.putChannel(channel);
}
}
}
@@ -403,8 +409,35 @@
{
// TODO - Don't write the entire file into memory. Use the stream-based
// methods on ChannelSftp once the work properly
+/*
final ChannelSftp channel = fileSystem.getChannel();
return new SftpOutputStream(channel);
+*/
+
+final ChannelSftp channel = fileSystem.getChannel();
+return new SftpOutputStream(channel, channel.put(relPath));
+}
+
+/**
+ * An InputStream that monitors for end-of-file.
+ */
+private class SftpInputStream extends MonitorInputStream
+{
+private final ChannelSftp channel;
+
+public SftpInputStream(final ChannelSftp channel, final InputStream in)
+{
+super(in);
+this.channel = channel;
+}
+
+/**
+ * Called after the stream has been closed.
+ */
+protected void onClose() throws IOException
+{
+fileSystem.putChannel(channel);
+}
}
/**
@@ -415,9 +448,9 @@
{
private final ChannelSftp channel;
-public SftpOutputStream(final ChannelSftp channel)
+public SftpOutputStream(final ChannelSftp channel, OutputStream out)
{
-super(new ByteArrayOutputStream());
+super(out);
this.channel = channel;
}
@@ -426,6 +459,7 @@
*/
protected void onClose() throws IOException
{
+/*
try
{
final ByteArrayOutputStream outstr = (ByteArrayOutputStream) out;
@@ -437,9 +471,11 @@
throw new FileSystemException(e);
}
finally
+*/
{
fileSystem.putChannel(channel);
}
}
}
+
}
●サーバ
open sshをインストール。
(Tcp Wrappersは入れなかったような...)
インストールすると、ユーザ、グループが追加される。
グループは削除してもいいが、ユーザは必要みたい(UIDは適当に振られるので、修正が必要)