可以确定用户主目录的父级名称吗?

我的Windows应用程序将文件上传到服务器,以便可以共享。为此,应用程序的用户需要在服务器上具有FTP特权的帐户。当站点管理员创建用户帐户时,会为他/她分配一个主目录(ftp登录),例如,用户的主目录可能是/ httpdocs / manual-uploads / SDJC。下面的代码显示了上传过程。

我的问题与如何共享上传的数据有关。 Windows应用程序执行上传后,它将生成一封电子邮件并将其发送给感兴趣的各方。电子邮件中嵌入了到上载文档的链接。链接如下所示:http://concoursbuilder.us/manual-uploads/SDJC/someDocument.pdf。在我看来,为了做到这一点,应用程序需要到父级的绝对(或相对?)路径。那么,如何做到这一点呢? printWorkingDirectory仅返回“ /”,任何尝试访问上游内容的尝试都会失败。例如,布尔值ok = ftpClient.changeWorkingDirectory(“ ..”)可以

让我想知道我是否正在尝试不可能的:-(。或者,我缺少什么?

顺便说一句,我知道我可以通过使User Home / httpdocs / manual-uploads然后对SDJC执行changeWorkingDirectory()来解决此问题。但是,这也将允许FTP访问其他用户目录。

代码如下:

public class FTPUploadDemoSimple {
public static void main(String[] args) {
    String server = "nx.dnslinks.net";
    int port = 21;
    String user = "asiteuser";  
    String pass = "apassword"; 
    FTPClient ftpClient = new FTPClient();
    try {
        ftpClient.connect(server,port);
        int replyCode = ftpClient.getReplyCode();
        if (!FTPReply.isPositiveCompletion(replyCode)) {
            System.out.println("Connect failed");
            return;
        }
        boolean success = ftpClient.login(user,pass);
        if (!success) {
            System.out.println("Could not login to the server");
            return;
        }
        System.out.println("CWD: " + ftpClient.printWorkingDirectory());
        String strLocalFile = "C:\\Users\\jag_m\\Documents\\FTPUploadTestData\\DataFiles\\ScheduleByJudge.pdf";
        ftpClient.enterLocalPassiveMode();
        ftpClient.setfileType(FTP.BINARY_FILE_TYPE);
        File localFile = new File(strLocalFile);
        InputStream inputStream = new FileInputStream(localFile);
        System.out.println("Start uploading " + strLocalFile);
        boolean done = ftpClient.storeFile(strLocalFile,inputStream);
        inputStream.close();
        if (done) {
            System.out.println(strLocalFile + " uploaded successfully.");
        }
        ftpClient.logout();
        ftpClient.disconnect();
    } catch (java.io.IOException ex) {
        Logger.getLogger(FTPUploadDemoSimple.class.getName()).log(Level.SEVERE,null,ex);
    }
}

}

g109007 回答:可以确定用户主目录的父级名称吗?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3099948.html

大家都在问