-
Notifications
You must be signed in to change notification settings - Fork 0
/
websters.cs
executable file
·219 lines (194 loc) · 5.54 KB
/
websters.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
using System;
using System.Collections;
using System.IO;
//using System.Text;
//using System.Security.Cryptography;//.X509Certificates;
//using System.Net;
//using System.Net.Sockets;
//using System.Runtime.InteropServices.DllImportAttribute;
//using FTPAUTHLib;
//ftplib.cpp:
//541,1568
namespace test
{
/// <summary>
/// This class connects to the DSHS immunization ssl-ftp server.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Starting...");
try
{
int i=1;
int IS;//isquared;
string IStemp;
string ISR="";//iSquaredReversed
double SROISR=0;//square root of ISR
string Itemp="";
string IRtemp="";
int IR=0; //iReversed
while (i<5000){
IS=i*i;
IStemp=IS.ToString();
for (int j=0; j<IStemp.Length; j++){
ISR = IStemp[j]+ISR;
SROISR = Math.Sqrt(Int32.Parse(ISR));
}
Itemp = i.ToString();
for (int k=0; k<Itemp.Length; k++){
IRtemp = Itemp[k]+IRtemp;
}
IR = Int32.Parse(IRtemp);
if (IR == SROISR)
Console.WriteLine("i="+i+"; i^2="+IS+"; i^2R="+ISR+
"; sqrt(i^2R)="+SROISR+"; iR="+IR);
i++;
ISR="";
IRtemp = "";
}
Console.ReadLine();
}
catch(Exception e)
{
Console.WriteLine("Caught Error :"+e.Message);
Console.ReadLine();
}
}
}
#region old stuff
/*
static Socket createSocket(string ipAddress, int port){
Socket ret = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint ep = new
IPEndPoint(Dns.Resolve(ipAddress).AddressList[0], port);
try
{
ret.Connect(ep);
}
catch(Exception)
{
Console.WriteLine("Can't connect to remote server");
}
return ret;
}
static string readLine(Socket clientSocket)
{
bool debug=false;
Encoding ASCII = Encoding.ASCII;
int bytes;
string mes ="";
int BLOCK_SIZE = 512;
Byte[] buffer = new Byte[BLOCK_SIZE];
while(true)
{
bytes = clientSocket.Receive(buffer, buffer.Length, 0);
mes += ASCII.GetString(buffer, 0, bytes);
if(bytes < buffer.Length)
{
break;
}
}
char[] seperator = {'\n'};
string[] mess = mes.Split(seperator);
if(mes.Length > 2)
{
mes = mess[mess.Length-2];
}
else
{
mes = mess[0];
}
if(!mes.Substring(3,1).Equals(" "))
{
return readLine(clientSocket);
}
if(debug)
{
for(int k=0;k < mess.Length-1;k++)
{
Console.WriteLine(mess[k]);
}
}
return mes;
}
static void sendCommand(String command, Socket clientSocket)
{
Byte[] cmdBytes =
Encoding.ASCII.GetBytes((command+"\r\n").ToCharArray());
clientSocket.Send(cmdBytes, cmdBytes.Length, 0);
}
static void sendAndPrint(String command, Socket clientSocket){
Console.WriteLine(command);
sendCommand(command, clientSocket);
Console.WriteLine(readLine(clientSocket));
}
*/
#endregion // old stuff
#region old stuff from main
/*
// The path to the certificate.
//string Certificate = @"C:\david\test\TXIR.crt";
//X509Certificate cert = X509Certificate.CreateFromCertFile(Certificate);
//Console.WriteLine(cert.ToString(true));
//Console.WriteLine(cert.ToString(false));
//string host = "ftp.jmjtech.com";
//string host = "immtrac-regserv.dshs.state.tx.us";
//string user= @"jmj\david.strube";
//string user= "abcpedi";
//string pass = "year2005";
//Console.WriteLine(Certificate);
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo(@"C:\david\ftps\scriptController.bat");
psi.RedirectStandardOutput = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
System.Diagnostics.Process listFiles;
listFiles = System.Diagnostics.Process.Start(psi);
System.IO.StreamReader myOutput = listFiles.StandardOutput;
listFiles.WaitForExit(2000);
if (listFiles.HasExited)
{
string output = myOutput.ReadToEnd();
Console.WriteLine(output);
=================================================================
//first 5 lines will always be the same
string line1 = "AUTH SSL 3"; //login for ssl type connection, only if certificate is on file
string line2 = "user abcpedi"; //username
string line3 = "pass year2005"; //password
//connect with parameters set, specified port:
string line4 = "connect immtrac-regserv.dshs.state.tx.us 1423";
string line5 = "cd submit"; //goto the submit folder
string lineX = @"put C:\david\ftps\test.txt /users/abcpedi/submit/test.txt 1";
ArrayList aL = new ArrayList();
aL.Add(line1);
aL.Add(line2);
aL.Add(line3);
aL.Add(line4);
aL.Add(line5);
//for (int j=0; j<=puts.Length; j++)
// aL.Add(puts[j]);
aL.Add(lineX);
aL.Add("close");
string filename = @"C:\david\ftps\2.scp";
if (File.Exists(filename))
{
Console.WriteLine("{0} already exists.", filename);
Console.ReadLine();
return;
}
StreamWriter sr = File.CreateText(filename);
for (int i=0; i<aL.Count; i++)
sr.WriteLine(aL[i]);
sr.Close();
//from http://blogs.msdn.com/csharpfaq/archive/2004/06/01/146375.aspx
//System.Diagnostics.Process.Start(@"C:\david\ftps\scriptController.bat");
*/
#endregion //old stuff from main
}