View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.provider.sftp;
18  
19  import java.io.File;
20  import java.io.Serializable;
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.commons.vfs2.FileSystem;
25  import org.apache.commons.vfs2.FileSystemConfigBuilder;
26  import org.apache.commons.vfs2.FileSystemException;
27  import org.apache.commons.vfs2.FileSystemOptions;
28  
29  import com.jcraft.jsch.ConfigRepository;
30  import com.jcraft.jsch.UserInfo;
31  
32  /**
33   * The config builder for various SFTP configuration options.
34   */
35  public final class SftpFileSystemConfigBuilder extends FileSystemConfigBuilder {
36  
37      private static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 0;
38      private static final int DEFAULT_SESSION_TIMEOUT_MILLIS = 0;
39  
40      /**
41       * Proxy type.
42       */
43      public static final class ProxyType implements Serializable, Comparable<ProxyType> {
44          /**
45           * serialVersionUID format is YYYYMMDD for the date of the last binary change.
46           */
47          private static final long serialVersionUID = 20101208L;
48  
49          private final String proxyType;
50  
51          private ProxyType(final String proxyType) {
52              this.proxyType = proxyType;
53          }
54  
55          @Override
56          public int compareTo(final ProxyType pType) {
57              return this.proxyType.compareTo(pType.proxyType);
58          }
59  
60          @Override
61          public boolean equals(final Object obj) {
62              if (this == obj) {
63                  return true;
64              }
65              if (obj == null || this.getClass() != obj.getClass()) {
66                  return false;
67              }
68  
69              final ProxyType pType = (ProxyType) obj;
70  
71              if (this.proxyType != null ? !this.proxyType.equals(pType.proxyType) : pType.proxyType != null) {
72                  return false;
73              }
74  
75              return true;
76          }
77  
78          /**
79           * @return a hash code value for this object.
80           * @since 2.0
81           */
82          @Override
83          public int hashCode() {
84              return this.proxyType.hashCode();
85          }
86      }
87  
88      private static final String _PREFIX = SftpFileSystemConfigBuilder.class.getName();
89      private static final SftpFileSystemConfigBuilderleSystemConfigBuilder.html#SftpFileSystemConfigBuilder">SftpFileSystemConfigBuilder BUILDER = new SftpFileSystemConfigBuilder();
90      private static final String COMPRESSION = _PREFIX + "COMPRESSION";
91      private static final String CONNECT_TIMEOUT_MILLIS = _PREFIX + ".CONNECT_TIMEOUT_MILLIS";
92      private static final String ENCODING = _PREFIX + ".ENCODING";
93      private static final String HOST_KEY_CHECK_ASK = "ask";
94      private static final String HOST_KEY_CHECK_NO = "no";
95      private static final String HOST_KEY_CHECK_YES = "yes";
96      private static final String IDENTITIES = _PREFIX + ".IDENTITIES";
97      private static final String IDENTITY_REPOSITORY_FACTORY = _PREFIX + "IDENTITY_REPOSITORY_FACTORY";
98      private static final String CONFIG_REPOSITORY = _PREFIX + "CONFIG_REPOSITORY";
99      private static final String KEY_EXCHANGE_ALGORITHM = _PREFIX + ".KEY_EXCHANGE_ALGORITHM";
100     private static final String LOAD_OPENSSH_CONFIG = _PREFIX + "LOAD_OPENSSH_CONFIG";
101     private static final String KNOWN_HOSTS = _PREFIX + ".KNOWN_HOSTS";
102     private static final String PREFERRED_AUTHENTICATIONS = _PREFIX + ".PREFERRED_AUTHENTICATIONS";
103     private static final String PROXY_COMMAND = _PREFIX + ".PROXY_COMMAND";
104     private static final String PROXY_HOST = _PREFIX + ".PROXY_HOST";
105     private static final String PROXY_OPTIONS = _PREFIX + ".PROXY_OPTIONS";
106     private static final String PROXY_PASSWORD = _PREFIX + ".PROXY_PASSWORD";
107     private static final String PROXY_PORT = _PREFIX + ".PROXY_PORT";
108 
109     /** HTTP Proxy. */
110     public static final ProxyType PROXY_HTTP = new ProxyType("http");
111 
112     /** SOCKS Proxy. */
113     public static final ProxyType PROXY_SOCKS5 = new ProxyType("socks");
114 
115     /**
116      * Connects to the SFTP server through a remote host reached by SSH.
117      * <p>
118      * On this proxy host, a command (e.g. {@linkplain SftpStreamProxy#NETCAT_COMMAND} or
119      * {@linkplain SftpStreamProxy#NETCAT_COMMAND}) is run to forward input/output streams between the target host and
120      * the VFS host.
121      * </p>
122      * <p>
123      * When used, the proxy username ({@linkplain #setProxyUser}) and hostname ({@linkplain #setProxyHost}) <b>must</b>
124      * be set. Optionnaly, the command ({@linkplain #setProxyCommand}), password ({@linkplain #setProxyPassword}) and
125      * connection options ({@linkplain #setProxyOptions}) can be set.
126      * </p>
127      */
128     public static final ProxyType PROXY_STREAM = new ProxyType("stream");
129 
130     private static final String PROXY_TYPE = _PREFIX + ".PROXY_TYPE";
131     private static final String PROXY_USER = _PREFIX + ".PROXY_USER";
132     private static final String SESSION_TIMEOUT_MILLIS = _PREFIX + ".TIMEOUT";
133     private static final String STRICT_HOST_KEY_CHECKING = _PREFIX + ".STRICT_HOST_KEY_CHECKING";
134     private static final String USER_DIR_IS_ROOT = _PREFIX + ".USER_DIR_IS_ROOT";
135 
136     /**
137      * Gets the singleton builder.
138      *
139      * @return the singleton builder.
140      */
141     public static SftpFileSystemConfigBuilder getInstance() {
142         return BUILDER;
143     }
144 
145     private SftpFileSystemConfigBuilder() {
146         super("sftp.");
147     }
148 
149     /**
150      * @param opts The FileSystem options.
151      * @return The names of the compression algorithms, comma-separated.
152      * @see #setCompression
153      */
154     public String getCompression(final FileSystemOptions opts) {
155         return this.getString(opts, COMPRESSION);
156     }
157 
158     @Override
159     protected Class<? extends FileSystem> getConfigClass() {
160         return SftpFileSystem.class;
161     }
162 
163     /**
164      * @param opts The FileSystem options.
165      * @return The connect timeout value in milliseconds.
166      * @see #setConnectTimeoutMillis
167      * @since 2.3
168      */
169     public Integer getConnectTimeoutMillis(final FileSystemOptions opts) {
170         return this.getInteger(opts, CONNECT_TIMEOUT_MILLIS, DEFAULT_CONNECT_TIMEOUT_MILLIS);
171     }
172 
173     /**
174      * Gets the file name encoding.
175      *
176      * @param opts The FileSystem options.
177      * @return the file name encoding
178      */
179     public String getFileNameEncoding(final FileSystemOptions opts) {
180         return this.getString(opts, ENCODING);
181     }
182 
183     /**
184      * Gets the identity files (your private key files).
185      * <p>
186      * We use java.io.File because JSch cannot deal with VFS FileObjects.
187      * </p>
188      *
189      * @param opts The FileSystem options.
190      * @return the array of identity Files.
191      * @see #setIdentities
192      * @deprecated As of 2.1 use {@link #getIdentityInfo(FileSystemOptions)}
193      */
194     @Deprecated
195     public File[] getIdentities(final FileSystemOptions opts) {
196         final IdentityInfo[] info = getIdentityInfo(opts);
197         if (info != null) {
198             final File[] files = new File[info.length];
199             for (int i = 0; i < files.length; ++i) {
200                 files[i] = info[i].getPrivateKey();
201             }
202             return files;
203         }
204         return null;
205     }
206 
207     /**
208      * Gets the identity infos.
209      *
210      * @param opts The FileSystem options.
211      * @return the array of identity info.
212      * @see #setIdentityInfo
213      */
214     public IdentityInfo[] getIdentityInfo(final FileSystemOptions opts) {
215         final IdentityProvider[] infos = getIdentityProvider(opts);
216         if (infos != null) {
217             final List<IdentityInfo> list = new ArrayList<>(infos.length);
218             for (IdentityProvider identityProvider : infos) {
219                 if (identityProvider instanceof IdentityInfo) {
220                     list.add((IdentityInfo) identityProvider);
221                 }
222             }
223             return list.toArray(new IdentityInfo[list.size()]);
224         }
225         return null;
226     }
227 
228     /**
229      * Gets the identity providers.
230      *
231      * @param opts The FileSystem options.
232      * @return the array of identity providers.
233      * @see #setIdentityProvider
234      * @since 2.4
235      */
236     public IdentityProvider[] getIdentityProvider(final FileSystemOptions opts) {
237         return (IdentityProvider[]) this.getParam(opts, IDENTITIES);
238     }
239 
240     /**
241      * Get the identity repository factory.
242      *
243      * @param opts The FileSystem options.
244      * @return the IdentityRepositoryFactory
245      */
246     public IdentityRepositoryFactory getIdentityRepositoryFactory(final FileSystemOptions opts) {
247         return (IdentityRepositoryFactory) this.getParam(opts, IDENTITY_REPOSITORY_FACTORY);
248     }
249 
250     /**
251      * Gets the config repository.
252      *
253      * @param opts The FileSystem options.
254      * @return the ConfigRepository
255      */
256     public ConfigRepository getConfigRepository(final FileSystemOptions opts) {
257         return (ConfigRepository) this.getParam(opts, CONFIG_REPOSITORY);
258     }
259 
260     /**
261      * Returns {@link Boolean#TRUE} if VFS should load the OpenSSH config. Defaults to <code>Boolean.FALSE</code> if the
262      * method {@link #setLoadOpenSSHConfig(FileSystemOptions, boolean)} has not been invoked.
263      *
264      * @param opts The FileSystemOptions.
265      * @return <code>Boolean.TRUE</code> if VFS should load the OpenSSH config.
266      * @see #setLoadOpenSSHConfig
267      */
268     public boolean isLoadOpenSSHConfig(final FileSystemOptions opts) {
269         return this.getBoolean(opts, LOAD_OPENSSH_CONFIG, Boolean.FALSE);
270     }
271 
272     /**
273      * @param opts The FileSystem options.
274      * @return the known hosts File.
275      * @see #setKnownHosts
276      */
277     public File getKnownHosts(final FileSystemOptions opts) {
278         return (File) this.getParam(opts, KNOWN_HOSTS);
279     }
280 
281     /**
282      * Gets authentication order.
283      *
284      * @param opts The FileSystem options.
285      * @return The authentication order.
286      * @since 2.0
287      */
288     public String getPreferredAuthentications(final FileSystemOptions opts) {
289         return getString(opts, PREFERRED_AUTHENTICATIONS);
290     }
291 
292     /**
293      * Gets the command that will be run on the proxy host when using a {@linkplain SftpStreamProxy}. The command
294      * defaults to {@linkplain SftpStreamProxy#NETCAT_COMMAND}.
295      *
296      * @param opts The FileSystem options.
297      * @return proxyOptions
298      * @see SftpStreamProxy
299      * @see #setProxyOptions
300      * @since 2.1
301      */
302     public String getProxyCommand(final FileSystemOptions opts) {
303         return this.getString(opts, PROXY_COMMAND, SftpStreamProxy.NETCAT_COMMAND);
304     }
305 
306     /**
307      * Gets the proxy to use for the SFTP connection.
308      *
309      * @param opts The FileSystem options.
310      * @return proxyHost
311      * @see #getProxyPort
312      * @see #setProxyHost
313      */
314     public String getProxyHost(final FileSystemOptions opts) {
315         return this.getString(opts, PROXY_HOST);
316     }
317 
318     /**
319      * Gets the proxy options that are used to connect to the proxy host.
320      *
321      * @param opts The FileSystem options.
322      * @return proxyOptions
323      * @see SftpStreamProxy
324      * @see #setProxyOptions
325      * @since 2.1
326      */
327     public FileSystemOptionshtml#FileSystemOptions">FileSystemOptions getProxyOptions(final FileSystemOptions opts) {
328         return (FileSystemOptions) this.getParam(opts, PROXY_OPTIONS);
329     }
330 
331     /**
332      * Gets the proxy password that are used to connect to the proxy host.
333      *
334      * @param opts The FileSystem options.
335      * @return proxyOptions
336      * @see SftpStreamProxy
337      * @see #setProxyPassword
338      * @since 2.1
339      */
340     public String getProxyPassword(final FileSystemOptions opts) {
341         return this.getString(opts, PROXY_PASSWORD);
342     }
343 
344     /**
345      * Gets the proxy-port to use for the SFTP the connection.
346      *
347      * @param opts The FileSystem options.
348      * @return proxyPort: the port number or 0 if it is not set
349      * @see #setProxyPort
350      * @see #getProxyHost
351      */
352     public int getProxyPort(final FileSystemOptions opts) {
353         return this.getInteger(opts, PROXY_PORT, 0);
354     }
355 
356     /**
357      * Gets the proxy type to use for the SFTP connection.
358      *
359      * @param opts The FileSystem options.
360      * @return The ProxyType.
361      */
362     public ProxyType getProxyType(final FileSystemOptions opts) {
363         return (ProxyType) this.getParam(opts, PROXY_TYPE);
364     }
365 
366     /**
367      * Gets the user name for the proxy used for the SFTP connection.
368      *
369      * @param opts The FileSystem options.
370      * @return proxyUser
371      * @see #setProxyUser
372      * @since 2.1
373      */
374     public String getProxyUser(final FileSystemOptions opts) {
375         return this.getString(opts, PROXY_USER);
376     }
377 
378     /**
379      * @param opts The FileSystem options.
380      * @return The session timeout value in milliseconds.
381      * @see #setSessionTimeoutMillis
382      * @since 2.3
383      */
384     public Integer getSessionTimeoutMillis(final FileSystemOptions opts) {
385         return this.getInteger(opts, SESSION_TIMEOUT_MILLIS, DEFAULT_SESSION_TIMEOUT_MILLIS);
386     }
387 
388     /**
389      * @param opts The FileSystem options.
390      * @return the option value The host key checking.
391      * @see #setStrictHostKeyChecking(FileSystemOptions, String)
392      */
393     public String getStrictHostKeyChecking(final FileSystemOptions opts) {
394         return this.getString(opts, STRICT_HOST_KEY_CHECKING, HOST_KEY_CHECK_NO);
395     }
396 
397     /**
398      * @param opts The FileSystem options.
399      * @return the option value for specific key exchange algorithm
400      * @see #setKeyExchangeAlgorithm(FileSystemOptions, String)
401      * @since 2.4
402      */
403     public String getKeyExchangeAlgorithm(final FileSystemOptions opts) {
404         return this.getString(opts, KEY_EXCHANGE_ALGORITHM);
405     }
406 
407     /**
408      * @param opts The FileSystem options.
409      * @return The timeout value in milliseconds.
410      * @see #setTimeout
411      * @deprecated Use {@link #getSessionTimeoutMillis(FileSystemOptions)}
412      */
413     @Deprecated
414     public Integer getTimeout(final FileSystemOptions opts) {
415         return this.getInteger(opts, SESSION_TIMEOUT_MILLIS);
416     }
417 
418     /**
419      * Returns {@link Boolean#TRUE} if VFS should treat the user directory as the root directory. Defaults to
420      * <code>Boolean.TRUE</code> if the method {@link #setUserDirIsRoot(FileSystemOptions, boolean)} has not been
421      * invoked.
422      *
423      * @param opts The FileSystemOptions.
424      * @return <code>Boolean.TRUE</code> if VFS treats the user directory as the root directory.
425      * @see #setUserDirIsRoot
426      */
427     public Boolean getUserDirIsRoot(final FileSystemOptions opts) {
428         return this.getBoolean(opts, USER_DIR_IS_ROOT, Boolean.TRUE);
429     }
430 
431     /**
432      * @param opts The FileSystem options.
433      * @return The UserInfo.
434      * @see #setUserInfo
435      */
436     public UserInfo getUserInfo(final FileSystemOptions opts) {
437         return (UserInfo) this.getParam(opts, UserInfo.class.getName());
438     }
439 
440     /**
441      * Configures the compression algorithms to use.
442      * <p>
443      * For example, use {@code "zlib,none"} to enable compression.
444      * </p>
445      * <p>
446      * See the Jsch documentation (in particular the README file) for details.
447      * </p>
448      *
449      * @param opts        The FileSystem options.
450      * @param compression The names of the compression algorithms, comma-separated.
451      * @throws FileSystemException if an error occurs.
452      */
453     public void setCompression(final FileSystemOptions opts, final String compression) throws FileSystemException {
454         this.setParam(opts, COMPRESSION, compression);
455     }
456 
457     /**
458      * Sets the timeout value to create a Jsch connection.
459      *
460      * @param opts    The FileSystem options.
461      * @param timeout The connect timeout in milliseconds.
462      * @since 2.3
463      */
464     public void setConnectTimeoutMillis(final FileSystemOptions opts, final Integer timeout) {
465         this.setParam(opts, CONNECT_TIMEOUT_MILLIS, timeout);
466     }
467 
468     /**
469      * Sets the file name encoding.
470      *
471      * @param opts             The FileSystem options.
472      * @param fileNameEncoding The name of the encoding to use for file names.
473      */
474     public void setFileNameEncoding(final FileSystemOptions opts, final String fileNameEncoding) {
475         this.setParam(opts, ENCODING, fileNameEncoding);
476     }
477 
478     /**
479      * Sets the identity files (your private key files).
480      * <p>
481      * We use {@link java.io.File} because JSch cannot deal with VFS FileObjects.
482      * </p>
483      *
484      * @param opts          The FileSystem options.
485      * @param identityFiles An array of identity Files.
486      * @throws FileSystemException if an error occurs.
487      * @deprecated As of 2.1 use {@link #setIdentityInfo(FileSystemOptions, IdentityInfo...)}
488      */
489     @Deprecated
490     public void setIdentities(final FileSystemOptions opts, final File... identityFiles) throws FileSystemException {
491         IdentityProvider[] info = null;
492         if (identityFiles != null) {
493             info = new IdentityProvider[identityFiles.length];
494             for (int i = 0; i < identityFiles.length; i++) {
495                 info[i] = new IdentityInfo(identityFiles[i]);
496             }
497         }
498         this.setParam(opts, IDENTITIES, info);
499     }
500 
501     /**
502      * Sets the identity info (your private key files).
503      *
504      * @param opts      The FileSystem options.
505      * @param identites An array of identity info.
506      * @throws FileSystemException if an error occurs.
507      * @since 2.1
508      * @deprecated Use {@link #setIdentityProvider(FileSystemOptions,IdentityProvider...)}
509      */
510     @Deprecated
511     public void setIdentityInfo(final FileSystemOptions opts, final IdentityInfo... identites)
512             throws FileSystemException {
513         this.setParam(opts, IDENTITIES, identites);
514     }
515 
516     /**
517      * Sets the identity info (your private key files).
518      *
519      * @param opts      The FileSystem options.
520      * @param identites An array of identity info.
521      * @throws FileSystemException if an error occurs.
522      * @since 2.4
523      */
524     public void setIdentityProvider(final FileSystemOptions opts, final IdentityProvider... identites)
525             throws FileSystemException {
526         this.setParam(opts, IDENTITIES, identites);
527     }
528 
529     /**
530      * Sets the identity repository.
531      * <p>
532      * This is useful when you want to use e.g. an SSH agent as provided.
533      * </p>
534      *
535      * @param opts    The FileSystem options.
536      * @param factory An identity repository.
537      * @throws FileSystemException if an error occurs.
538      * @see <a href="http://www.jcraft.com/jsch-agent-proxy/">JSch agent proxy</a>
539      */
540     public void setIdentityRepositoryFactory(final FileSystemOptions opts, final IdentityRepositoryFactory factory)
541             throws FileSystemException {
542         this.setParam(opts, IDENTITY_REPOSITORY_FACTORY, factory);
543     }
544 
545     /**
546      * Sets the config repository. e.g. {@code /home/user/.ssh/config}.
547      * <p>
548      * This is useful when you want to use OpenSSHConfig.
549      * </p>
550      *
551      * @param opts             The FileSystem options.
552      * @param configRepository An config repository.
553      * @throws FileSystemException if an error occurs.
554      * @see <a href="http://www.jcraft.com/jsch/examples/OpenSSHConfig.java.html">OpenSSHConfig</a>
555      */
556     public void setConfigRepository(final FileSystemOptions opts, final ConfigRepository configRepository)
557             throws FileSystemException {
558         this.setParam(opts, CONFIG_REPOSITORY, configRepository);
559     }
560 
561     /**
562      * Sets the known_hosts file. e.g. {@code /home/user/.ssh/known_hosts2}.
563      * <p>
564      * We use {@link java.io.File} because JSch cannot deal with VFS FileObjects.
565      * </p>
566      *
567      * @param opts       The FileSystem options.
568      * @param knownHosts The known hosts file.
569      * @throws FileSystemException if an error occurs.
570      */
571     public void setKnownHosts(final FileSystemOptions opts, final File knownHosts) throws FileSystemException {
572         this.setParam(opts, KNOWN_HOSTS, knownHosts);
573     }
574 
575     /**
576      * Configures authentication order.
577      *
578      * @param opts                     The FileSystem options.
579      * @param preferredAuthentications The authentication order.
580      * @since 2.0
581      */
582     public void setPreferredAuthentications(final FileSystemOptions opts, final String preferredAuthentications) {
583         this.setParam(opts, PREFERRED_AUTHENTICATIONS, preferredAuthentications);
584     }
585 
586     /**
587      * Sets the proxy username to use for the SFTP connection.
588      *
589      * @param opts         The FileSystem options.
590      * @param proxyCommand the port
591      * @see #getProxyOptions
592      * @since 2.1
593      */
594     public void setProxyCommand(final FileSystemOptions opts, final String proxyCommand) {
595         this.setParam(opts, PROXY_COMMAND, proxyCommand);
596     }
597 
598     /**
599      * Sets the proxy to use for the SFTP connection.
600      *
601      * You MUST also set the proxy port to use the proxy.
602      *
603      * @param opts      The FileSystem options.
604      * @param proxyHost the host
605      * @see #setProxyPort
606      */
607     public void setProxyHost(final FileSystemOptions opts, final String proxyHost) {
608         this.setParam(opts, PROXY_HOST, proxyHost);
609     }
610 
611     /**
612      * Sets the proxy username to use for the SFTP connection.
613      *
614      * @param opts         The FileSystem options.
615      * @param proxyOptions the options
616      * @see #getProxyOptions
617      * @since 2.1
618      */
619     public void setProxyOptions(final FileSystemOptionsemOptions.html#FileSystemOptions">FileSystemOptions opts, final FileSystemOptions proxyOptions) {
620         this.setParam(opts, PROXY_OPTIONS, proxyOptions);
621     }
622 
623     /**
624      * Sets the proxy password to use for the SFTP connection.
625      *
626      * @param opts          The FileSystem options.
627      * @param proxyPassword the username used to connect to the proxy
628      * @see #getProxyPassword
629      * @since 2.1
630      */
631     public void setProxyPassword(final FileSystemOptions opts, final String proxyPassword) {
632         this.setParam(opts, PROXY_PASSWORD, proxyPassword);
633     }
634 
635     /**
636      * Sets the proxy port to use for the SFTP connection.
637      * <p>
638      * You MUST also set the proxy host to use the proxy.
639      * </p>
640      *
641      * @param opts      The FileSystem options.
642      * @param proxyPort the port
643      * @see #setProxyHost
644      */
645     public void setProxyPort(final FileSystemOptions opts, final int proxyPort) {
646         this.setParam(opts, PROXY_PORT, Integer.valueOf(proxyPort));
647     }
648 
649     /**
650      * Sets the proxy type to use for the SFTP connection.
651      * <p>
652      * The possibles values are:
653      * </p>
654      * <ul>
655      * <li>{@linkplain #PROXY_HTTP} connects using an HTTP proxy</li>
656      * <li>{@linkplain #PROXY_SOCKS5} connects using an Socket5 proxy</li>
657      * <li>{@linkplain #PROXY_STREAM} connects through a remote host stream command</li>
658      * </ul>
659      *
660      * @param opts      The FileSystem options.
661      * @param proxyType the type of the proxy to use.
662      */
663     public void setProxyType(final FileSystemOptions opts, final ProxyType proxyType) {
664         this.setParam(opts, PROXY_TYPE, proxyType);
665     }
666 
667     /**
668      * Sets the proxy username to use for the SFTP connection.
669      *
670      * @param opts      The FileSystem options.
671      * @param proxyUser the username used to connect to the proxy
672      * @see #getProxyUser
673      * @since 2.1
674      */
675     public void setProxyUser(final FileSystemOptions opts, final String proxyUser) {
676         this.setParam(opts, PROXY_USER, proxyUser);
677     }
678 
679     /**
680      * Sets the timeout value on Jsch session.
681      *
682      * @param opts    The FileSystem options.
683      * @param timeout The session timeout in milliseconds.
684      * @since 2.3
685      */
686     public void setSessionTimeoutMillis(final FileSystemOptions opts, final Integer timeout) {
687         this.setParam(opts, SESSION_TIMEOUT_MILLIS, timeout);
688     }
689 
690     /**
691      * Configures Key exchange algorithm explicitly e.g diffie-hellman-group14-sha1,
692      * diffie-hellman-group-exchange-sha256, diffie-hellman-group-exchange-sha1, diffie-hellman-group1-sha1
693      *
694      * @param opts                The FileSystem options.
695      * @param keyExchangeAlgoritm The key exchange algorithm picked.
696      * @since 2.4
697      */
698     public void setKeyExchangeAlgorithm(final FileSystemOptions opts, final String keyExchangeAlgoritm) {
699         setParam(opts, KEY_EXCHANGE_ALGORITHM, keyExchangeAlgoritm);
700     }
701 
702     /**
703      * Configures the host key checking to use.
704      * <p>
705      * Valid arguments are: {@code "yes"}, {@code "no"} and {@code "ask"}.
706      * </p>
707      * <p>
708      * See the jsch documentation for details.
709      * </p>
710      *
711      * @param opts            The FileSystem options.
712      * @param hostKeyChecking The host key checking to use.
713      * @throws FileSystemException if an error occurs.
714      */
715     public void setStrictHostKeyChecking(final FileSystemOptions opts, final String hostKeyChecking)
716             throws FileSystemException {
717         if (hostKeyChecking == null || (!hostKeyChecking.equals(HOST_KEY_CHECK_ASK)
718                 && !hostKeyChecking.equals(HOST_KEY_CHECK_NO) && !hostKeyChecking.equals(HOST_KEY_CHECK_YES))) {
719             throw new FileSystemException("vfs.provider.sftp/StrictHostKeyChecking-arg.error", hostKeyChecking);
720         }
721 
722         this.setParam(opts, STRICT_HOST_KEY_CHECKING, hostKeyChecking);
723     }
724 
725     /**
726      * Sets the timeout value on Jsch session.
727      *
728      * @param opts    The FileSystem options.
729      * @param timeout The timeout in milliseconds.
730      * @deprecated Use {@link #setSessionTimeoutMillis(FileSystemOptions, Integer)}
731      */
732     @Deprecated
733     public void setTimeout(final FileSystemOptions opts, final Integer timeout) {
734         this.setParam(opts, SESSION_TIMEOUT_MILLIS, timeout);
735     }
736 
737     /**
738      * Sets the whether to use the user directory as root (do not change to file system root).
739      *
740      * @param opts          The FileSystem options.
741      * @param userDirIsRoot true if the user directory is the root directory.
742      */
743     public void setUserDirIsRoot(final FileSystemOptions opts, final boolean userDirIsRoot) {
744         this.setParam(opts, USER_DIR_IS_ROOT, userDirIsRoot ? Boolean.TRUE : Boolean.FALSE);
745     }
746 
747     /**
748      * Sets the Jsch UserInfo class to use.
749      *
750      * @param opts The FileSystem options.
751      * @param info User information.
752      */
753     public void setUserInfo(final FileSystemOptions opts, final UserInfo info) {
754         this.setParam(opts, UserInfo.class.getName(), info);
755     }
756 
757     /**
758      * Sets the whether to load OpenSSH config.
759      *
760      * @param opts              The FileSystem options.
761      * @param loadOpenSSHConfig true if the OpenSSH config should be loaded.
762      */
763     public void setLoadOpenSSHConfig(final FileSystemOptions opts, final boolean loadOpenSSHConfig) {
764         this.setParam(opts, LOAD_OPENSSH_CONFIG, loadOpenSSHConfig ? Boolean.TRUE : Boolean.FALSE);
765     }
766 }