简体   繁体   English

如何快速上传图像文件到FTP服务器?

[英]how to upload image file to FTP server in swift?

I am using Gold Raccoon in my swift project.我在我的 swift 项目中使用Gold Raccoon My swift code builds and runs fine but when I check on the FTP Server there is no file.我的 swift 代码构建并运行良好,但是当我检查 FTP 服务器时没有文件。 This is the code which I am using in viewDidload()这是我在 viewDidload() 中使用的代码

  var ftpRequest:GRRequestsManager!
  var  path  = NSBundle.mainBundle().pathForResource("marker", ofType: ".png")

  ftpRequest = GRRequestsManager(hostname: "192.x.x.x", user: "xx", password: "xxxx")
  ftpRequest.addRequestForUploadFileAtLocalPath(path, toRemotePath: "/marker.png")
  self.ftpRequest.startProcessingRequests()

Then I tried to check whether my file is successully uploaded or not by using delegate of GRRequestsManager ftpRequest.delegate = self in viewDidload().然后我尝试通过在 viewDidload() 中使用 GRRequestsManager ftpRequest.delegate = self委托来检查我的文件是否成功上传。 and wrote these delegate functions in my swift class by conforming with GRRequestsManagerDelegate protocol.并通过符合GRRequestsManagerDelegate协议在我的 swift 类中编写了这些委托函数。

 func requestsManager(requestsManager: GRRequestsManagerProtocol!, didCompleteUploadRequest request: GRDataExchangeRequestProtocol!) {
            print("did Complete Upload Request")
        }
   func requestsManager(requestsManager: GRRequestsManagerProtocol!, didFailRequest request: GRRequestProtocol!, withError error: NSError!) {
            print("did Fail Request")
        }

when I compile its fine but when I run the code xcode gives me an error on this line ftpRequest.delegate = self当我编译它很好但是当我运行代码时 xcode 在这一行ftpRequest.delegate = self给了我一个错误

unexpectedly found nil意外发现 nil

I cannot upload my .png file to the FTP Server.我无法将我的 .png 文件上传到 FTP 服务器。 Allover the internet that I found is about Obj-C but NO swift code to do this.我发现整个互联网都是关于 Obj-C 但没有快速代码来做到这一点。

Is there any swift way to do this?有什么快速的方法可以做到这一点吗?

Please guide me If I am doing wrong.如果我做错了,请指导我。 Or provide any running sample code that uploads the .png file to the FTP Server with Authentication(should require username and password)或者提供任何正在运行的示例代码,将 .png 文件上传到带有身份验证的 FTP 服务器(应该需要用户名和密码)

NOTE : I am using Briding Header to use GoldRaccoon (as it is available only in Objective-C)注意:我使用 Briding Header 来使用GoldRaccoon (因为它仅在 Objective-C 中可用)

Finally my problem is solved I just used Rebekka Touch framework which is a swift framework.最后我的问题解决了我只使用了Rebekka Touch 框架,这是一个 swift 框架。 Its is easy to use and really a very good thing.它易于使用,确实是一件非常好的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM