annotate src/ch/ethz/ssh2/SCPClient.java @ 305:d2b303406d63 ganymed

remove extra override annotations that generate eclipse compiler errors
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 12:09:51 -0700
parents 855cdc3b2ced
children 071eccdff8ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
1 package ch.ethz.ssh2;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
2
292
855cdc3b2ced start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 290
diff changeset
3 import java.io.BufferedInputStream;
855cdc3b2ced start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 290
diff changeset
4 import java.io.BufferedOutputStream;
855cdc3b2ced start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 290
diff changeset
5 import java.io.File;
855cdc3b2ced start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 290
diff changeset
6 import java.io.FileInputStream;
855cdc3b2ced start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 290
diff changeset
7 import java.io.FileOutputStream;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8 import java.io.IOException;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
9 import java.io.InputStream;
292
855cdc3b2ced start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 290
diff changeset
10 import java.io.OutputStream;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 import java.nio.charset.Charset;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
12 import java.nio.charset.UnsupportedCharsetException;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
13
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
14 /**
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
15 * A very basic <code>SCPClient</code> that can be used to copy files from/to
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16 * the SSH-2 server. On the server side, the "scp" program must be in the PATH.
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17 * <p/>
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18 * This scp client is thread safe - you can download (and upload) different sets
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19 * of files concurrently without any troubles. The <code>SCPClient</code> is
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20 * actually mapping every request to a distinct {@link ch.ethz.ssh2.Session}.
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21 *
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 * @author Christian Plattner, plattner@inf.ethz.ch
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 * @version $Id: SCPClient.java 85 2014-04-07 14:05:09Z dkocher@sudo.ch $
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 */
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
25
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
26 public class SCPClient
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 Connection conn;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
29
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30 String charsetName = null;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
31
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
32 /**
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
33 * Set the charset used to convert between Java Unicode Strings and byte encodings
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
34 * used by the server for paths and file names.
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
35 *
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
36 * @param charset the name of the charset to be used or <code>null</code> to use the platform's
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
37 * default encoding.
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
38 * @throws IOException
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
39 * @see #getCharset()
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
40 */
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
41 public void setCharset(String charset) throws IOException
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
43 if (charset == null)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45 charsetName = charset;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
46 return;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
47 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
48
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 try
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
50 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
51 Charset.forName(charset);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 catch (UnsupportedCharsetException e)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
55 throw new IOException("This charset is not supported", e);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
56 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
57 charsetName = charset;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
58 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
59
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60 /**
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
61 * The currently used charset for filename encoding/decoding.
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
62 *
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
63 * @return The name of the charset (<code>null</code> if the platform's default charset is being used)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
64 * @see #setCharset(String)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
65 */
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
66 public String getCharset()
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
68 return charsetName;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
69 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
70
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
71 public class LenNamePair
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
72 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
73 public long length;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
74 String filename;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
75 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
76
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
77 public SCPClient(Connection conn)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
78 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
79 if (conn == null)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
80 throw new IllegalArgumentException("Cannot accept null argument!");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
81 this.conn = conn;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
82 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
83
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
84 protected void readResponse(InputStream is) throws IOException
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
85 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
86 int c = is.read();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
87
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
88 if (c == 0)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
89 return;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
90
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
91 if (c == -1)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
92 throw new IOException("Remote scp terminated unexpectedly.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
93
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
94 if ((c != 1) && (c != 2))
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
95 throw new IOException("Remote scp sent illegal error code.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
96
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
97 if (c == 2)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
98 throw new IOException("Remote scp terminated with error.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
99
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
100 String err = receiveLine(is);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
101 throw new IOException("Remote scp terminated with error (" + err + ").");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
102 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
103
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
104 protected String receiveLine(InputStream is) throws IOException
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
105 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
106 StringBuilder sb = new StringBuilder(30);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
107
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
108 while (true)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
109 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
110 /* This is a random limit - if your path names are longer, then adjust it */
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
111
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
112 if (sb.length() > 8192)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
113 throw new IOException("Remote scp sent a too long line");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
114
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
115 int c = is.read();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
116
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
117 if (c < 0)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
118 throw new IOException("Remote scp terminated unexpectedly.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
119
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
120 if (c == '\n')
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
121 break;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
122
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
123 sb.append((char) c);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
124
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
125 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
126 return sb.toString();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
127 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
128
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
129 protected LenNamePair parseCLine(String line) throws IOException
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
130 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
131 /* Minimum line: "xxxx y z" ---> 8 chars */
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
132
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
133 if (line.length() < 8)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
134 throw new IOException("Malformed C line sent by remote SCP binary, line too short.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
135
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
136 if ((line.charAt(4) != ' ') || (line.charAt(5) == ' '))
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
137 throw new IOException("Malformed C line sent by remote SCP binary.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
138
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
139 int length_name_sep = line.indexOf(' ', 5);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
140
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
141 if (length_name_sep == -1)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
142 throw new IOException("Malformed C line sent by remote SCP binary.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
143
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
144 String length_substring = line.substring(5, length_name_sep);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
145 String name_substring = line.substring(length_name_sep + 1);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
146
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
147 if ((length_substring.length() <= 0) || (name_substring.length() <= 0))
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
148 throw new IOException("Malformed C line sent by remote SCP binary.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
149
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
150 if ((6 + length_substring.length() + name_substring.length()) != line.length())
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
151 throw new IOException("Malformed C line sent by remote SCP binary.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
152
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
153 final long len;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
154 try
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
155 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
156 len = Long.parseLong(length_substring);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
157 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
158 catch (NumberFormatException e)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
159 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
160 throw new IOException("Malformed C line sent by remote SCP binary, cannot parse file length.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
161 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
162
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
163 if (len < 0)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
164 throw new IOException("Malformed C line sent by remote SCP binary, illegal file length.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
165
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
166 LenNamePair lnp = new LenNamePair();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
167 lnp.length = len;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
168 lnp.filename = name_substring;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
169
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
170 return lnp;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
171 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
172
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
173 /**
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
174 * The session for opened for this SCP transfer must be closed using
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
175 * SCPOutputStream#close
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
176 *
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
177 * @param remoteFile
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
178 * @param length The size of the file to send
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
179 * @param remoteTargetDirectory
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
180 * @param mode
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
181 * @return
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
182 * @throws IOException
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
183 */
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
184 public SCPOutputStream put(final String remoteFile, long length, String remoteTargetDirectory, String mode)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
185 throws IOException
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
186 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
187 Session sess = null;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
188
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
189 if (null == remoteFile)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
190 throw new IllegalArgumentException("Null argument.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
191 if (null == remoteTargetDirectory)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
192 remoteTargetDirectory = "";
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
193 if (null == mode)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
194 mode = "0600";
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
195 if (mode.length() != 4)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
196 throw new IllegalArgumentException("Invalid mode.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
197
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
198 for (int i = 0; i < mode.length(); i++)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
199 if (Character.isDigit(mode.charAt(i)) == false)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
200 throw new IllegalArgumentException("Invalid mode.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
201
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
202 remoteTargetDirectory = (remoteTargetDirectory.length() > 0) ? remoteTargetDirectory : ".";
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
203
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
204 String cmd = "scp -t -d \"" + remoteTargetDirectory + "\"";
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
205
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
206 sess = conn.openSession();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
207 sess.execCommand(cmd, charsetName);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
208
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
209 return new SCPOutputStream(this, sess, remoteFile, length, mode);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
210 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
211
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
212 /**
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
213 * The session for opened for this SCP transfer must be closed using
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
214 * SCPInputStream#close
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
215 *
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
216 * @param remoteFile
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
217 * @return
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
218 * @throws IOException
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
219 */
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
220 public SCPInputStream get(final String remoteFile) throws IOException
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
221 {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
222 Session sess = null;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
223
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
224 if (null == remoteFile)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
225 throw new IllegalArgumentException("Null argument.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
226
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
227 if (remoteFile.length() == 0)
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
228 throw new IllegalArgumentException("Cannot accept empty filename.");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
229
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
230 String cmd = "scp -f";
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
231 cmd += (" \"" + remoteFile + "\"");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
232
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
233 sess = conn.openSession();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
234 sess.execCommand(cmd, charsetName);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
235
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
236 return new SCPInputStream(this, sess);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
237 }
290
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
238 private void sendBytes(Session sess, byte[] data, String fileName, String mode) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
239 OutputStream os = sess.getStdin();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
240 InputStream is = new BufferedInputStream(sess.getStdout(), 512);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
241 readResponse(is);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
242 String cline = "C" + mode + " " + data.length + " " + fileName + "\n";
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
243 os.write(cline.getBytes("ISO-8859-1"));
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
244 os.flush();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
245 readResponse(is);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
246 os.write(data, 0, data.length);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
247 os.write(0);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
248 os.flush();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
249 readResponse(is);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
250 os.write("E\n".getBytes("ISO-8859-1"));
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
251 os.flush();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
252 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
253
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
254 private void sendFiles(Session sess, String[] files, String[] remoteFiles, String mode) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
255 byte[] buffer = new byte[8192];
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
256 OutputStream os = new BufferedOutputStream(sess.getStdin(), 40000);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
257 InputStream is = new BufferedInputStream(sess.getStdout(), 512);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
258 readResponse(is);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
259
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
260 for (int i = 0; i < files.length; i++) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
261 File f = new File(files[i]);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
262 long remain = f.length();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
263 String remoteName;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
264
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
265 if ((remoteFiles != null) && (remoteFiles.length > i) && (remoteFiles[i] != null))
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
266 remoteName = remoteFiles[i];
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
267 else
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
268 remoteName = f.getName();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
269
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
270 String cline = "C" + mode + " " + remain + " " + remoteName + "\n";
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
271 os.write(cline.getBytes("ISO-8859-1"));
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
272 os.flush();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
273 readResponse(is);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
274 FileInputStream fis = null;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
275
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
276 try {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
277 fis = new FileInputStream(f);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
278
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
279 while (remain > 0) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
280 int trans;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
281
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
282 if (remain > buffer.length)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
283 trans = buffer.length;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
284 else
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
285 trans = (int) remain;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
286
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
287 if (fis.read(buffer, 0, trans) != trans)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
288 throw new IOException("Cannot read enough from local file " + files[i]);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
289
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
290 os.write(buffer, 0, trans);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
291 remain -= trans;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
292 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
293 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
294 finally {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
295 if (fis != null)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
296 fis.close();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
297 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
298
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
299 os.write(0);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
300 os.flush();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
301 readResponse(is);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
302 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
303
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
304 os.write("E\n".getBytes("ISO-8859-1"));
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
305 os.flush();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
306 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
307
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
308 private void receiveFiles(Session sess, OutputStream[] targets) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
309 byte[] buffer = new byte[8192];
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
310 OutputStream os = new BufferedOutputStream(sess.getStdin(), 512);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
311 InputStream is = new BufferedInputStream(sess.getStdout(), 40000);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
312 os.write(0x0);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
313 os.flush();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
314
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
315 for (int i = 0; i < targets.length; i++) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
316 LenNamePair lnp = null;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
317
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
318 while (true) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
319 int c = is.read();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
320
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
321 if (c < 0)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
322 throw new IOException("Remote scp terminated unexpectedly.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
323
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
324 String line = receiveLine(is);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
325
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
326 if (c == 'T') {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
327 /* Ignore modification times */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
328 continue;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
329 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
330
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
331 if ((c == 1) || (c == 2))
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
332 throw new IOException("Remote SCP error: " + line);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
333
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
334 if (c == 'C') {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
335 lnp = parseCLine(line);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
336 break;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
337 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
338
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
339 throw new IOException("Remote SCP error: " + ((char) c) + line);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
340 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
341
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
342 os.write(0x0);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
343 os.flush();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
344 long remain = lnp.length;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
345
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
346 while (remain > 0) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
347 int trans;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
348
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
349 if (remain > buffer.length)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
350 trans = buffer.length;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
351 else
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
352 trans = (int) remain;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
353
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
354 int this_time_received = is.read(buffer, 0, trans);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
355
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
356 if (this_time_received < 0) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
357 throw new IOException("Remote scp terminated connection unexpectedly");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
358 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
359
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
360 targets[i].write(buffer, 0, this_time_received);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
361 remain -= this_time_received;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
362 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
363
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
364 readResponse(is);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
365 os.write(0x0);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
366 os.flush();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
367 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
368 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
369
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
370 private void receiveFiles(Session sess, String[] files, String target) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
371 byte[] buffer = new byte[8192];
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
372 OutputStream os = new BufferedOutputStream(sess.getStdin(), 512);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
373 InputStream is = new BufferedInputStream(sess.getStdout(), 40000);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
374 os.write(0x0);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
375 os.flush();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
376
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
377 for (int i = 0; i < files.length; i++) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
378 LenNamePair lnp = null;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
379
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
380 while (true) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
381 int c = is.read();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
382
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
383 if (c < 0)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
384 throw new IOException("Remote scp terminated unexpectedly.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
385
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
386 String line = receiveLine(is);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
387
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
388 if (c == 'T') {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
389 /* Ignore modification times */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
390 continue;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
391 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
392
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
393 if ((c == 1) || (c == 2))
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
394 throw new IOException("Remote SCP error: " + line);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
395
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
396 if (c == 'C') {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
397 lnp = parseCLine(line);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
398 break;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
399 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
400
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
401 throw new IOException("Remote SCP error: " + ((char) c) + line);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
402 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
403
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
404 os.write(0x0);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
405 os.flush();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
406 File f = new File(target + File.separatorChar + lnp.filename);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
407 FileOutputStream fop = null;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
408
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
409 try {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
410 fop = new FileOutputStream(f);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
411 long remain = lnp.length;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
412
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
413 while (remain > 0) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
414 int trans;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
415
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
416 if (remain > buffer.length)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
417 trans = buffer.length;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
418 else
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
419 trans = (int) remain;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
420
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
421 int this_time_received = is.read(buffer, 0, trans);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
422
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
423 if (this_time_received < 0) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
424 throw new IOException("Remote scp terminated connection unexpectedly");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
425 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
426
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
427 fop.write(buffer, 0, this_time_received);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
428 remain -= this_time_received;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
429 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
430 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
431 finally {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
432 if (fop != null)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
433 fop.close();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
434 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
435
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
436 readResponse(is);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
437 os.write(0x0);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
438 os.flush();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
439 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
440 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
441
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
442 /**
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
443 * Copy a local file to a remote directory, uses mode 0600 when creating the
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
444 * file on the remote side.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
445 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
446 * @param localFile
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
447 * Path and name of local file.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
448 * @param remoteTargetDirectory
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
449 * Remote target directory. Use an empty string to specify the
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
450 * default directory.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
451 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
452 * @throws IOException
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
453 */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
454 public void put(String localFile, String remoteTargetDirectory) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
455 put(new String[] { localFile }, remoteTargetDirectory, "0600");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
456 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
457
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
458 /**
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
459 * Copy a set of local files to a remote directory, uses mode 0600 when
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
460 * creating files on the remote side.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
461 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
462 * @param localFiles
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
463 * Paths and names of local file names.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
464 * @param remoteTargetDirectory
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
465 * Remote target directory. Use an empty string to specify the
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
466 * default directory.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
467 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
468 * @throws IOException
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
469 */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
470
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
471 public void put(String[] localFiles, String remoteTargetDirectory) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
472 put(localFiles, remoteTargetDirectory, "0600");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
473 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
474
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
475 /**
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
476 * Copy a local file to a remote directory, uses the specified mode when
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
477 * creating the file on the remote side.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
478 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
479 * @param localFile
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
480 * Path and name of local file.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
481 * @param remoteTargetDirectory
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
482 * Remote target directory. Use an empty string to specify the
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
483 * default directory.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
484 * @param mode
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
485 * a four digit string (e.g., 0644, see "man chmod", "man open")
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
486 * @throws IOException
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
487 */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
488 public void put(String localFile, String remoteTargetDirectory, String mode) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
489 put(new String[] { localFile }, remoteTargetDirectory, mode);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
490 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
491
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
492 /**
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
493 * Copy a local file to a remote directory, uses the specified mode and
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
494 * remote filename when creating the file on the remote side.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
495 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
496 * @param localFile
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
497 * Path and name of local file.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
498 * @param remoteFileName
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
499 * The name of the file which will be created in the remote
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
500 * target directory.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
501 * @param remoteTargetDirectory
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
502 * Remote target directory. Use an empty string to specify the
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
503 * default directory.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
504 * @param mode
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
505 * a four digit string (e.g., 0644, see "man chmod", "man open")
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
506 * @throws IOException
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
507 */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
508 public void put(String localFile, String remoteFileName, String remoteTargetDirectory, String mode)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
509 throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
510 put(new String[] { localFile }, new String[] { remoteFileName }, remoteTargetDirectory, mode);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
511 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
512
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
513 /**
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
514 * Create a remote file and copy the contents of the passed byte array into
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
515 * it. Uses mode 0600 for creating the remote file.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
516 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
517 * @param data
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
518 * the data to be copied into the remote file.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
519 * @param remoteFileName
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
520 * The name of the file which will be created in the remote
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
521 * target directory.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
522 * @param remoteTargetDirectory
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
523 * Remote target directory. Use an empty string to specify the
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
524 * default directory.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
525 * @throws IOException
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
526 */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
527
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
528 public void put(byte[] data, String remoteFileName, String remoteTargetDirectory) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
529 put(data, remoteFileName, remoteTargetDirectory, "0600");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
530 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
531
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
532 /**
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
533 * Create a remote file and copy the contents of the passed byte array into
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
534 * it. The method use the specified mode when creating the file on the
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
535 * remote side.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
536 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
537 * @param data
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
538 * the data to be copied into the remote file.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
539 * @param remoteFileName
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
540 * The name of the file which will be created in the remote
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
541 * target directory.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
542 * @param remoteTargetDirectory
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
543 * Remote target directory. Use an empty string to specify the
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
544 * default directory.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
545 * @param mode
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
546 * a four digit string (e.g., 0644, see "man chmod", "man open")
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
547 * @throws IOException
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
548 */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
549 public void put(byte[] data, String remoteFileName, String remoteTargetDirectory, String mode) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
550 Session sess = null;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
551
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
552 if ((remoteFileName == null) || (remoteTargetDirectory == null) || (mode == null))
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
553 throw new IllegalArgumentException("Null argument.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
554
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
555 if (mode.length() != 4)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
556 throw new IllegalArgumentException("Invalid mode.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
557
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
558 for (int i = 0; i < mode.length(); i++)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
559 if (Character.isDigit(mode.charAt(i)) == false)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
560 throw new IllegalArgumentException("Invalid mode.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
561
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
562 remoteTargetDirectory = remoteTargetDirectory.trim();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
563 remoteTargetDirectory = (remoteTargetDirectory.length() > 0) ? remoteTargetDirectory : ".";
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
564 String cmd = "scp -t -d " + remoteTargetDirectory;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
565
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
566 try {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
567 sess = conn.openSession();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
568 sess.execCommand(cmd);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
569 sendBytes(sess, data, remoteFileName, mode);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
570 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
571 catch (IOException e) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
572 throw(IOException) new IOException("Error during SCP transfer.").initCause(e);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
573 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
574 finally {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
575 if (sess != null)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
576 sess.close();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
577 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
578 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
579
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
580 /**
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
581 * Copy a set of local files to a remote directory, uses the specified mode
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
582 * when creating the files on the remote side.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
583 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
584 * @param localFiles
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
585 * Paths and names of the local files.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
586 * @param remoteTargetDirectory
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
587 * Remote target directory. Use an empty string to specify the
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
588 * default directory.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
589 * @param mode
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
590 * a four digit string (e.g., 0644, see "man chmod", "man open")
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
591 * @throws IOException
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
592 */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
593 public void put(String[] localFiles, String remoteTargetDirectory, String mode) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
594 put(localFiles, null, remoteTargetDirectory, mode);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
595 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
596
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
597 public void put(String[] localFiles, String[] remoteFiles, String remoteTargetDirectory, String mode)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
598 throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
599 Session sess = null;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
600
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
601 /*
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
602 * remoteFiles may be null, indicating that the local filenames shall be
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
603 * used
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
604 */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
605
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
606 if ((localFiles == null) || (remoteTargetDirectory == null) || (mode == null))
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
607 throw new IllegalArgumentException("Null argument.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
608
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
609 if (mode.length() != 4)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
610 throw new IllegalArgumentException("Invalid mode.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
611
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
612 for (int i = 0; i < mode.length(); i++)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
613 if (Character.isDigit(mode.charAt(i)) == false)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
614 throw new IllegalArgumentException("Invalid mode.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
615
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
616 if (localFiles.length == 0)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
617 return;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
618
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
619 remoteTargetDirectory = remoteTargetDirectory.trim();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
620 remoteTargetDirectory = (remoteTargetDirectory.length() > 0) ? remoteTargetDirectory : ".";
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
621 String cmd = "scp -t -d " + remoteTargetDirectory;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
622
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
623 for (int i = 0; i < localFiles.length; i++) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
624 if (localFiles[i] == null)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
625 throw new IllegalArgumentException("Cannot accept null filename.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
626 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
627
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
628 try {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
629 sess = conn.openSession();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
630 sess.execCommand(cmd);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
631 sendFiles(sess, localFiles, remoteFiles, mode);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
632 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
633 catch (IOException e) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
634 throw(IOException) new IOException("Error during SCP transfer.").initCause(e);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
635 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
636 finally {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
637 if (sess != null)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
638 sess.close();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
639 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
640 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
641
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
642 /**
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
643 * Download a file from the remote server to a local directory.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
644 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
645 * @param remoteFile
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
646 * Path and name of the remote file.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
647 * @param localTargetDirectory
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
648 * Local directory to put the downloaded file.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
649 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
650 * @throws IOException
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
651 */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
652 public void get(String remoteFile, String localTargetDirectory) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
653 get(new String[] { remoteFile }, localTargetDirectory);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
654 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
655
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
656 /**
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
657 * Download a file from the remote server and pipe its contents into an
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
658 * <code>OutputStream</code>. Please note that, to enable flexible usage
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
659 * of this method, the <code>OutputStream</code> will not be closed nor
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
660 * flushed.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
661 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
662 * @param remoteFile
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
663 * Path and name of the remote file.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
664 * @param target
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
665 * OutputStream where the contents of the file will be sent to.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
666 * @throws IOException
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
667 */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
668 public void get(String remoteFile, OutputStream target) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
669 get(new String[] { remoteFile }, new OutputStream[] { target });
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
670 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
671
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
672 private void get(String remoteFiles[], OutputStream[] targets) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
673 Session sess = null;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
674
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
675 if ((remoteFiles == null) || (targets == null))
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
676 throw new IllegalArgumentException("Null argument.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
677
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
678 if (remoteFiles.length != targets.length)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
679 throw new IllegalArgumentException("Length of arguments does not match.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
680
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
681 if (remoteFiles.length == 0)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
682 return;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
683
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
684 String cmd = "scp -f";
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
685
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
686 for (int i = 0; i < remoteFiles.length; i++) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
687 if (remoteFiles[i] == null)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
688 throw new IllegalArgumentException("Cannot accept null filename.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
689
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
690 String tmp = remoteFiles[i].trim();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
691
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
692 if (tmp.length() == 0)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
693 throw new IllegalArgumentException("Cannot accept empty filename.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
694
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
695 cmd += (" " + tmp);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
696 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
697
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
698 try {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
699 sess = conn.openSession();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
700 sess.execCommand(cmd);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
701 receiveFiles(sess, targets);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
702 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
703 catch (IOException e) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
704 throw(IOException) new IOException("Error during SCP transfer.").initCause(e);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
705 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
706 finally {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
707 if (sess != null)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
708 sess.close();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
709 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
710 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
711
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
712 /**
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
713 * Download a set of files from the remote server to a local directory.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
714 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
715 * @param remoteFiles
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
716 * Paths and names of the remote files.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
717 * @param localTargetDirectory
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
718 * Local directory to put the downloaded files.
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
719 *
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
720 * @throws IOException
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
721 */
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
722 public void get(String remoteFiles[], String localTargetDirectory) throws IOException {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
723 Session sess = null;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
724
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
725 if ((remoteFiles == null) || (localTargetDirectory == null))
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
726 throw new IllegalArgumentException("Null argument.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
727
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
728 if (remoteFiles.length == 0)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
729 return;
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
730
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
731 String cmd = "scp -f";
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
732
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
733 for (int i = 0; i < remoteFiles.length; i++) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
734 if (remoteFiles[i] == null)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
735 throw new IllegalArgumentException("Cannot accept null filename.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
736
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
737 String tmp = remoteFiles[i].trim();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
738
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
739 if (tmp.length() == 0)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
740 throw new IllegalArgumentException("Cannot accept empty filename.");
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
741
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
742 cmd += (" " + tmp);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
743 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
744
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
745 try {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
746 sess = conn.openSession();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
747 sess.execCommand(cmd);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
748 receiveFiles(sess, remoteFiles, localTargetDirectory);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
749 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
750 catch (IOException e) {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
751 throw(IOException) new IOException("Error during SCP transfer.").initCause(e);
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
752 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
753 finally {
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
754 if (sess != null)
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
755 sess.close();
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
756 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
757 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
758 }
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
759
9ae4ed7bb523 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
760