//サーバー上のテキストファイルを1行読み取る public string GetFileLine(string From_File, bool IsErrorLogMode = false) { if (!IsConnected) { return(""); } else if (!SFTP_Server.IsConnected) { SFTP_Server.Connect(); } try { StreamReader str = SFTP_Server.OpenText(From_File); string GetLine = str.ReadLine(); str.Dispose(); return(GetLine); } catch (Exception e) { if (IsErrorLogMode) { Sub_Code.Error_Log_Write(e.Message); } return(""); } }
/// <summary> /// 获取文件 /// </summary> /// <param name="remotePath"></param> /// <returns></returns> public StreamReader Get(string localPath) { try { Connect(); StreamReader reader = sftp.OpenText(localPath); return(reader); } catch (Exception ex) { throw new Exception(string.Format("SFTP文件获取失败,原因:{0}", ex.Message)); } }
public void OpenTextTest() { ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value string path = string.Empty; // TODO: Initialize to an appropriate value StreamReader expected = null; // TODO: Initialize to an appropriate value StreamReader actual; actual = target.OpenText(path); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
App GetItunesMetadata(SftpClient client, string dir) { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); var app = new App(); var appFullPath = Path.Combine(dir, FindAppInDirectory(client, dir)); stopwatch.Start(); var path = Path.Combine(appFullPath, "Info.plist"); stopwatch.Stop(); Debug.Log("FindAppInDirectory (" + dir + "): " + stopwatch.ElapsedMilliseconds); if (!client.Exists(path)) { Debug.LogError("Failed to find file at: " + path); var appSplit = path.Split('/'); var appDir = appSplit[appSplit.Length - 2]; return(new App(appDir, "")); // return null; } stopwatch.Reset(); stopwatch.Start(); TextReader tr = client.OpenText(path); var strPListFile = tr.ReadToEnd(); stopwatch.Stop(); Debug.Log("ReadFile (" + dir + "): " + stopwatch.ElapsedMilliseconds); // Debug.Log(strPListFile); var plist = new PList(); try { plist = new PList(strPListFile); } catch (Exception e) { Debug.Log("Failed to parse at: " + path + ", Exception: " + e); // var appSplit = path.Split('/'); // var appDir = appSplit[appSplit.Length - 2]; // return new App(appDir, "", ""); return(null); } if (plist.ContainsKey("CFBundleDisplayName")) { app.name = plist["CFBundleDisplayName"]; } else { app.name = plist["CFBundleName"]; } app.version = plist["CFBundleVersion"]; app.path = appFullPath; return(app); }