2020import net .schmizz .sshj .xfer .LocalFileFilter ;
2121import net .schmizz .sshj .xfer .LocalSourceFile ;
2222import net .schmizz .sshj .xfer .TransferListener ;
23+ import net .schmizz .sshj .xfer .scp .ScpCommandLine .Arg ;
2324
2425import java .io .IOException ;
2526import java .io .InputStream ;
@@ -43,37 +44,44 @@ public synchronized int copy(LocalSourceFile sourceFile, String remotePath)
4344 return copy (sourceFile , remotePath , ScpCommandLine .EscapeMode .SingleQuote );
4445 }
4546
46- public synchronized int copy (LocalSourceFile sourceFile , String remotePath , ScpCommandLine .EscapeMode escapeMode ) throws IOException {
47+ public synchronized int copy (LocalSourceFile sourceFile , String remotePath , ScpCommandLine .EscapeMode escapeMode )
48+ throws IOException {
4749 return copy (sourceFile , remotePath , escapeMode , true );
4850 }
4951
5052 public synchronized int copy (LocalSourceFile sourceFile , String remotePath , ScpCommandLine .EscapeMode escapeMode , boolean preserveTimes )
51- throws IOException {
53+ throws IOException {
54+ ScpCommandLine commandLine = ScpCommandLine .with (ScpCommandLine .Arg .SINK )
55+ .and (ScpCommandLine .Arg .RECURSIVE )
56+ .and (ScpCommandLine .Arg .LIMIT , String .valueOf (bandwidthLimit ), (bandwidthLimit > 0 ));
57+ if (preserveTimes ) {
58+ commandLine .and (ScpCommandLine .Arg .PRESERVE_TIMES , sourceFile .providesAtimeMtime ());
59+ }
60+ return copy (sourceFile , remotePath , escapeMode , commandLine );
61+ }
62+
63+ public synchronized int copy (LocalSourceFile sourceFile , String remotePath , ScpCommandLine .EscapeMode escapeMode , ScpCommandLine commandLine )
64+ throws IOException {
5265 engine .cleanSlate ();
5366 try {
54- startCopy (sourceFile , remotePath , escapeMode , preserveTimes );
67+ commandLine .withPath (remotePath , escapeMode );
68+ startCopy (sourceFile , commandLine );
5569 } finally {
5670 engine .exit ();
5771 }
5872 return engine .getExitStatus ();
5973 }
6074
75+
6176 public void setUploadFilter (LocalFileFilter uploadFilter ) {
6277 this .uploadFilter = uploadFilter ;
6378 }
6479
65- private void startCopy (LocalSourceFile sourceFile , String targetPath , ScpCommandLine . EscapeMode escapeMode , boolean preserveTimes )
80+ private void startCopy (LocalSourceFile sourceFile , ScpCommandLine commandLine )
6681 throws IOException {
67- ScpCommandLine commandLine = ScpCommandLine .with (ScpCommandLine .Arg .SINK )
68- .and (ScpCommandLine .Arg .RECURSIVE )
69- .and (ScpCommandLine .Arg .LIMIT , String .valueOf (bandwidthLimit ), (bandwidthLimit > 0 ));
70- if (preserveTimes ) {
71- commandLine .and (ScpCommandLine .Arg .PRESERVE_TIMES , sourceFile .providesAtimeMtime ());
72- }
73- commandLine .withPath (targetPath , escapeMode );
7482 engine .execSCPWith (commandLine );
7583 engine .check ("Start status OK" );
76- process (engine .getTransferListener (), sourceFile , preserveTimes );
84+ process (engine .getTransferListener (), sourceFile , commandLine . has ( Arg . PRESERVE_TIMES ) );
7785 }
7886
7987 private void process (TransferListener listener , LocalSourceFile f , boolean preserveTimes )
0 commit comments